Content-Type header value for PDFs for Azure OCR Read API - azure-cognitive-services

I am trying to call /vision/v3.1/read/analyze API with a PDF, but sending Content-Type header as application/pdf or application/octet-stream is giving an InvalidImage error. What should be the header value ? Any code sample that I can refer to ?

The supported Content-Types are application/json- analyze images from URL and application/octet-stream - analyze images from disk. I tried the Read API reference and provided url for a pdf file. Confirmed using Get Read Result and works fine. Check out available code samples in python, tutorial and c#, tutorial.

Related

How to upload a file which name contains special characters using JMeter?

I struggle to upload files using a POST HTTP request in JMeter, which file name (not file content) contains special characters such as "é è à". For example: "nameWithSpecialCharacters_éè.txt".
Is this a limitation of JMeter? I'm on 5.5 version (latest as of now).
Thank you for your help.
I tried several things such as putting file.encoding=UTF-8 in JMeter settings. I also put UTF-8 in "Content encoding" in HTTP Request sampler but none of these work... I have the same issue if I use BeanShell PreProcessor and set the files to upload with sampler.setHTTPFiles(filesToUpload)
No matter what I do the characters are replaced by "?" in the body of the request:
Content-Disposition: form-data; name="file1"; filename="nameWithSpecialCharacters_??.txt" Content-Type: text/plain Content-Transfer-Encoding: binary
It looks like a bug in the HttpClient4 implementation, I would suggest raising it via JMeter Issues
In the meantime as a workaround you could switch your HTTP Request sampler to use Java as the implementation:
If you have more than one HTTP Request sampler you could use HTTP Request Defaults to perform the change in one place for all.

Need to parse binary pdf data from a REST API postback and save it in filesystem or in mysql db

below is example of postback message. I am posting data to a party using spring rest. In return they will send me raw pdf data along with postback message. How do I read this pdf data and download the pdf file in browser on request at later time.
Appreciate your help with the code.
of I am reference text
------------d0f32ac86c8249c9aa562c1fcfbfeb66
Content-Disposition: form-data; name="filename"
Bk-40274-tx17-Mess.pdf
------------d0f32ac86c8249c9aa562c1fcfbfeb66
Content-Disposition: form-data; name="fileformat"
pdf
------------d0f32ac86c8249c9aa562c1fcfbfeb66
Content-Disposition: form-data; name="file"; filename="Bk-40274-tx17-Mess.pdf"
Content-Type: application/pdf
You need to create UploadRestController that will receive pdf content.You can follow below link to develop your UploadRestController.
Spring : File Upload RESTFUL Web Service
Your UploadRestController will save file somewhere in file system and its file path/other stuff matadata in DB or Cache.
Develop another DownloadRestController that will give you PDF whenever requested.It will read file from file system using metadata and will set response.You can follow below link to develop DownloadRestController.
Return generated pdf using spring MVC

web api Odata v4 content negotiation for excel

Based off this stackoverflow post, is it possible to setup odata so that when can accept header of 'application/vnd.ms-excel'is request, the endpoint would return an excel spreadsheet with the power query data source set in the downloaded doc without hard coding every endpoint to check the headers for an accept type?
if not, what is the best way handle the content negotiation to export to excel.
Web API OData only supports application/json and application/atom+xml out of the box. If you want to support application/vnd.ms-excel in your service, you will have to implement a custom MediaTypeFormatter. See How to provide custom mediatype formats for OData Api.

What does a Http response for serving a binary file (.swf) look like?

I need to serve a file on localhost to a certain application which only accepts http URI-s. However, the files are generated on the fly and I would like to avoid writing to disk, so I decided to write a simple HTTP server using QTcpServer. Luckily, I even found a nice tutorial explaining just that. However, I'm not familiar with HTTP responses. How do I serve a flash file? Is there a particular MIME type for that? And after putting the header together, do I just dump the stream to the socket and that's all?
The mime type you are looking for is: application/x-shockwave-flash
What you need to set is
Set the content type to application/x-shockwave-flash
Set the content length to the total size of the swf to serve
Set the header with content disposition like: Content-Disposition=attachment;filename=SWFToServe.swf
Start writing out all the bytes of the swf file.
Flush the response
And that's all, the client should start downloading it...
This doesn't answer your complete question but you can look for MIME type here:
http://www.w3schools.com/media/media_mimeref.asp
SWF is application/x-shockwave-flash

HTTP file uploading standard?

I'm writing a client in python to upload a file to a webserver I run. On the PHP side, it seems I should expect the file to arrive in the $_FILES variable, but I can't find any documentation on how that variable gets populated. I can find tutorials on how to create web forms to upload, but none of them tell me what the actual HTTP POST looks like. I'm assuming that there is a standard for what parameters to populate and what content-type to specify, but I can't find it stated anywhere.
It's the multipart/form-data encoding which is described in RFC 1867 and RFC 2388.

Resources