Get pdf with GET and POST the file in next request

I’m having trouble using the file from a GET request and then sending the file in the next POST request. It’s a pdf file if that makes any difference.

I can also access the pdf file by URL, so it would be easiest if I could specify a URL for the file data, instead of a locally saved file.

Any help would be appreciated.

Hi @myrso.

You can specify the URL of the file in the address bar and send a GET request to the file without doing anything else.

What errors do you get when you send the POST request in the screenshot you shared?

Hello. Thank you for the response. I am successfully getting the file with GET, but then need to use that same file in the next POST request (ideally without downloading the file locally). The error I am getting when I try to end the POST request is:

{

“code”: 3660,

“message”: “No file found in the request. Please include a file and try again.”

}

If I understand you correctly, what you are trying to do is to upload a file to a server using the URL of the file directly on Postman.

This is an interesting use case, but I do not think Postman currently supports it.

Ideally, when you upload a file using form-data or binary over an HTTP request, what you send is a blob or a base64 string of the file. Postman makes this more convenient by allowing you to select a file locally and does the conversion for you when you make a request.

I am guessing that you are using this file in an automation flow which is why you want to avoid downloading it locally?

My solution might be quite hacky but it works. It involves you first converting the file to base64 when it is fetched, then you save this in your environment. You can then retrieve this base64 string from your environment when you want to upload it.

  1. Create an environment for this and add a convenient variable name. In my case, I used filebase64.

  1. Send a GET request to the image and add some postman scripts to the Test tab which runs after the file has been fetched. The script simply gets the base64 of the file using the dataURI method and saves it in the environment.
const image = pm.response.dataURI()

pm.environment.set("filebase64", image);

NOTE: Don’t forget to toggle the right environment by the top right.

Now, each time you fetch a file, it gets the base64 equivalent text of that file and saves it as an environment variable.

  1. Post the base64 text saved in your environment to your server.

You will notice that this base64 text is in the echoed response, which means it got sent.

I created a public collection for this example. You can check it out here.

Let me know if it works for you!

Thank you!!!, I will try this tomorrow. What would be theoretical maximum PDF file size be using this method? I imagine there is a limit to the max string length for variables?

Greeaaatt!

Let me know however it goes.

The maximum payload size should be mostly dependent on the server. Some servers default to 100kb, but it can be increased. Postman allows you to send up to 50MB by default, but this can be increased in the settings tab.

I do not know if there is a limit to how much data can be stored in an environment variable, but I did a quick search and saw someone who stored over 200kb which is quite good.

I gave it a try, but I’m getting the following error:

{“code”:2945,“description”:“MORE_THAN_MAX_LENGTH”}

The API I am using is https://www.zoho.com/creator/help/api/v2/upload-file.html

I gave it a try, but I’m getting the following error:

{“code”:2945,“description”:“MORE_THAN_MAX_LENGTH”}

The API I am using is https://www.zoho.com/creator/help/api/v2/upload-file.html

What is the size of the file you’re trying to upload?

39kb, but it will be different for each request.

This seems like a Zoho specific error rather than a Postman error.

I checked the API link you sent and I see that the Zoho API allows you upload a file as a multipart/form-data by specifying it’s URL.

In the sample collection I shared, I think you can just update the variable to the image URL and it should work.

I might be wrong. I haven’t worked with the Zoho API before. But that is what it seems like to me.

Hi, regarding “Zoho API allows you upload a file as a multipart/form-data by specifying it’s URL.”. Where did you see this documentation? I have tried many times without luck.

I saw it here.