Currently we are trying to retrieve a file from an API call. The return type of response.content from the API is binary/octet-stream but from the zapier its transforming as string. We tried the Content-Type in the zapier requests header but its throwing an error. With the string format some characters are not encoding properly. so we want to retrieve it same as the API send. How can we achieve this?
How to change the return response from zapier requests?
Hi
Are you asking about your Download Files trigger?
Have you tried using `z.stashFile`? I think that’s going to be more helpful than trying to change the return response.
We have some documentation on stashing files here that you might find helpful, and one of the examples even mentions binary/octet. This goes along with other documentation on hydration and dehydration and this example app for files might be helpful as well.
Hi
Hi
Oh yeah, you’re right. I was thinking (but didn’t make explicit) that then you’d be able to return it kind of like this example to result in a file. Basically a hack where you could then download it this way.
Have you tried setting the raw: true flag as done in that stashing files example? That is also the approach used in the downloadFile hydrator used by the example I just linked above.
![](https://uploads-us-west-2.insided.com/zapier-ca/attachment/29281fdc-390b-48fd-9db8-879d23e7e21b.png)
Yes after I tried the raw:true. I got new error
Error: You passed {raw: true} in request() - the response.content property is not available! Try response.body.pipe() for streaming, response.buffer() for a buffer, or response.text() for string.
In pipe() what should we pass?
Here is my code
const response = await z.request(url: API_URL, method: 'GET', raw: true,
);return { content: response.body.pipe(NOT_SURE_WHAT_TO_PASS_HERE) };
Hey
- App ID
- Filename within that app which contains the code you’re working on
The error message you’ve seen here sounds like the code might either be referring to `response` before the promise assigned to it has resolved, or the `response` doesn’t contain a `content` property as the code expects. Once we can take a look at your code within context, we’ll be better positioned to get you pointed in the right direction.
In general, I’d suggest modelling your app off these examples:
`newFile.js` is an example trigger which downloads a file from a URL using `z.dehydrateFile()`:
![](https://uploads-us-west-2.insided.com/zapier-ca/attachment/245550a5-7f2d-42bc-a0ba-689469e6db4e.png)
We can see that this method takes two input parameters; a `downloadFile` promise and an object containing the URL of the file. The `downloadFile` promise is defined in the `hydrators.js` file, which is where the HTTP request for the actual file is made:
![](https://uploads-us-west-2.insided.com/zapier-ca/attachment/784638b3-1603-4f59-a33a-a21822f39ea2.png)
And the response to that request (the file data) is stashed, so that we return a URL pointing to the stash file:
![](https://uploads-us-west-2.insided.com/zapier-ca/attachment/661fbca2-9f83-4884-a63b-b97de25b8e40.png)
I hope this helps!
App ID: 167973
filename: download-file.js (/actions/contract/download-files.js)
I tried the stashing it returning the URL, but my case want the content of the file instead the URL.
Thanks for confirming that,
It looks like your app differs in a few ways from the example, so I think your next steps should be refactoring the code such that:
- The `perform` method for the “DownloadFiles” action returns an object containing a property named “file”
- The “file” property is populated by a call to `z.dehydrateFile()`
- `z.dehydrateFile()` is fed two input parameters; a function to download the file and an object containing the URL of the file to be downloaded (more info on this is here)
The function to download the file (named `hydrators.downloadFile` in the example) should make an asynchronous HTTP call using `z.request()` and can optionally stash the file and return a URL. Since you’ve mentioned that you’d prefer the actual file object is returned to the Zap, you can omit the `raw: true` property and call to `z.stashFile()`.
Once complete, the result will look like the examples given in this tutorial which I believe demonstrates the outcome you’re looking for :)
Thanks for the answer
I have pushed my latest version of code. Will you able to take a look?
Lavarthan,
Are you saying that you are getting the file, except the file does not have an image in it?
Hm, that is confusing. Are you able to download the full file through curl or Postman and get the image in it? Can you see the request being made in the Monitoring tab and compare it to what you’re doing in curl or Postman to look for any differences (in headers or anything else?)
You also might be able to get eyes on this by reaching out to our platform support team directly here.
Even though when I return the file URL(when you open in browser you can download the file) instead of the file content and tried to save it on Dropbox its working fine.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.