Upload file test with Postman - postman

I am testing a file upload to SharePoint online with Postman. In my post request I set the body to form-data and add a file param with a text file called a.txt. The text file contains the text
one
two
three
When I execute the request my file is uploaded but when I open the file the contents is
----------------------------235004993628819232914336
Content-Disposition: form-data; name="file"; filename="a.txt"
Content-Type: text/plain
one
two
three
----------------------------235004
I have tried setting the Content-Type header to
application/x-www-form-urlencoded
or
multipart/form-data
But no luck

Please follow the below steps-
1. Go to the body of the API
2. pass the parameter or key
3. When you pass the key you have a option of value of Text/File like below
4.Choose the file from
5. Click on send.
6. Get your response.
Hope this helps buddy.

In my case setting the body to type binary solved my problem with testing with Postman

Related

AWS Web Servers some PDF Files don't display on the webpage, instead they automatically download

Good day,
I'm currently trying to display PDF files in an iFrame but for some reason, they just auto-download whenever I visit the links.
Here's a file which auto-downloads:
Here's a file which displays as normal:
The difference between your 2 files is the Content-Type:
The first has Content-Type: application/octet-stream
The second has Content-Type: application/pdf
application/octet-stream is considered an unknown binary file and browsers download it directly (https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#applicationoctet-stream).
You can fix it by going to the S3 console and changing the first file Content-Type metadata to application/pdf.
More information on editing metadata: https://docs.aws.amazon.com/AmazonS3/latest/userguide/add-object-metadata.html

Postman - How to embed a file as base64 string in a POST multipart/form-data request?

I would like to share my Postman-Collection including a multipart/form-data request with a very specific file so everything is contained within the Postman-Collection itself.
I tried several approaches like setting the value to text and adding the picture in base64 format and setting the content-type to image/jpeg;base64 or prefixing the value with base64,<base64encodedString> and several combinations that I could think of, but to no avail.
The only documentation/hint I found was setting a postman variable that contains a dynamic definition of where the file is located - this does not solve my problem here though.
How do I embed a file within a Postman multipart/form-data request?
In postman multiform you can upload a file by hovering over the field and selecting type as file.
Example :
change type to file from text. Also enable the column content-type ( it will be generated automatically you don't have to chagne anything)
Other examples:
https://apidocs.imgur.com/
The above has a demo endpoint shows how to upload a image.

how to store postman respone content-type:- text/plain to a variable?

on hitting the API request using GET method, i get the response content-type as text/plain; and it is a token (example:- ejusgjksdflksdfkjdfksdhfkds). how to store this response token to a variable using script in postman.
Any test script for this?
Thanks.
derived from #danny's answer in the comments,
use pm.response.text() when the response header type is text/plain.
ex:
pm.globals.set("my-token", pm.response.text());
console.log(pm.globals.get("my-token")); // the variable value will outputs to postman console

Parse multipart/form-data json body of lambda in Java

I am trying to implement a Lambda function that receives a POST request containing data encoded as multipart/form-data. The message is received through the API Gateway using Lambda Proxy integration and the body is encoded in Base64 when it arrives to the Lambda function. After decoding it manually, I see it contains a multipart body like the following:
-----WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="param1"
value1
-----WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="param2"
value2
------WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="myfile"; filename="ivr.png"
Content-Type: image/png
PNG
... [binary stuff]
------WebKitFormBoundary3EZ0C3tbP2JpAmz4--
What I need is to parse this message in java 8.
so that I can access the individual parts like
1. form data
2 file content
I have tried fileupload, Apache Multipart those didn't workout
Any sols will be helpful.
I ran into a similar issue with my application. I used and modified a custom form-data parser here: https://apimeister.com/2015/10/10/formdatahandler-implements-com-sun-net-httpserver-httphandler.html
I got it to parse properly however, the binary data came in malformed similar to this issue here: https://github.com/dherault/serverless-offline/issues/230
How did you get the entire AWS Lambda body to encode to base64? Can you post instructions to do so? That may fix the malformed data issue I am running into.

Force S3 PDF to be viewed in browser instead of download

So you can force a download by using Content-Disposition: attachment
Content-Disposition: inline is the default and should display in the browser, and it does in fact work with most files like PNG, JPG, etc.
But for some reason somehow when generating a presigned URL from S3, PDF files will always force download even if I don't use the content-disposition: attachment header.
I want to be able to make the PDF open in the browser when the browser allows it
I am using the presigned URL generate call from S3 client http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html
Check you file's metadata and remove Content-Disposition entry from that file. and set content type according to the file type.
Like for
text file Content-Type='text/plain'
image png Content-Type='image/png'
pdf Content-Type=application/pdf
pdfxml Content-Type=application/vnd.adobe.pdfxml
If your file's Content-Type is binary/octet-stream then it will download instead of display.
Thanks
You have to set your putObject params as follows to view pdf instead of download.
params = {
Bucket: process.env.S3_BUCKET,
Key: <fileName>,
Body: <fileContent>,
ContentDisposition:"inline",
ContentType:"application/pdf"
};
You also need to set the Content-Type correctly. The browser will check the content-type value, and if it isn't something it knows how to display it will always just download the file.
You need to provide both these meta data inorder to view the file instead of download:
Content-Disposition: attachment
Content-Type: application/pdf