# Force downloads

**URL:** <https://community.parseplatform.org/t/force-downloads/2528>\
**Category:** Parse Server 📡\
**Created:** [March 22, 2022, 4:21pm UTC](https://community.parseplatform.org/t/force-downloads/2528 "2022-03-22T16:21:39Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunobg](https://community.parseplatform.org/user_avatar/community.parseplatform.org/brunobg/32/967_2.png) [@brunobg](https://community.parseplatform.org/u/brunobg)\
**Post date:** [March 22, 2022, 4:21pm UTC](https://community.parseplatform.org/t/force-downloads/2528/1 "2022-03-22T16:21:39Z")

</div>

Is there any way to force downloads on files served by parse? Basically I want to extend the `/parse/files/:appId/:filename` route to add a custom header that forces a download, but I can’t find an easy way to do that.

I ended up writing a separate endpoint that essentially does `response.end(await fileObject.getData())`, but my files are in S3 and this takes a while. But I’m guessing it downloads the whole file locally first and only then starts sending data to the client browser, which is very unresponsive.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [March 23, 2022, 3:41pm UTC](https://community.parseplatform.org/t/force-downloads/2528/2 "2022-03-23T15:41:40Z")

</div>

Have you tried to use the directAccess option? It will make the client to download directly from s3 and not pass through your server at all.

---

<div class="post-metadata">

**Author:** ![brunobg](https://community.parseplatform.org/user_avatar/community.parseplatform.org/brunobg/32/967_2.png) [@brunobg](https://community.parseplatform.org/u/brunobg)\
**Post date:** [March 23, 2022, 7:03pm UTC](https://community.parseplatform.org/t/force-downloads/2528/3 "2022-03-23T19:03:44Z")

</div>

Unfortunately directAccess will avoid any grant checks and it’s a global option that affects the entire applications. I need something a little more fine grained than that.

---

<div class="post-metadata">

**Author:** ![davimacedo](https://community.parseplatform.org/user_avatar/community.parseplatform.org/davimacedo/32/316_2.png) [@davimacedo](https://community.parseplatform.org/u/davimacedo)\
**Post date:** [March 23, 2022, 11:09pm UTC](https://community.parseplatform.org/t/force-downloads/2528/4 "2022-03-23T23:09:59Z")

</div>

So the file will have to pass through your server, what will probably reduce the performance (in comparison to direct access to s3). What you can try to do to speed is, instead of awaiting the whole file to be download before starting the transfer to the client, is create a stream to send file while it is still being received.

---

<div class="post-metadata">

**Author:** ![Manuel](https://community.parseplatform.org/user_avatar/community.parseplatform.org/manuel/32/186_2.png) [@Manuel](https://community.parseplatform.org/u/Manuel)\
**Post date:** [March 24, 2022, 2:53am UTC](https://community.parseplatform.org/t/force-downloads/2528/5 "2022-03-24T02:53:54Z")

</div>

What you could also consider is a CDN. It will save you costs, decrease download times for clients if you distribute the files in multiple geo-regions and they are usually highly configurable, allowing you to add various headers conditionally, manage streaming or do even image processing on the fly.

---

<div class="post-metadata">

**Author:** ![brunobg](https://community.parseplatform.org/user_avatar/community.parseplatform.org/brunobg/32/967_2.png) [@brunobg](https://community.parseplatform.org/u/brunobg)\
**Post date:** [March 24, 2022, 12:18pm UTC](https://community.parseplatform.org/t/force-downloads/2528/6 "2022-03-24T12:18:26Z")

</div>

Is there a way to get access to the file adapter data given a `Parse.File` object?

---

<div class="post-metadata">

**Author:** ![dblythy](https://community.parseplatform.org/user_avatar/community.parseplatform.org/dblythy/32/231_2.png) [@dblythy](https://community.parseplatform.org/u/dblythy)\
**Post date:** [March 24, 2022, 2:03pm UTC](https://community.parseplatform.org/t/force-downloads/2528/7 "2022-03-24T14:03:10Z")

</div>

I believe there was a PR relating changing the headers / adding `application/octet-stream` to the file get route.

> <https://github.com/parse-community/parse-server/issues/7572>
>
> \### New Issue Checklist
> \<!--
> Check every following box \[x\] before submitti…ng your issue.
> Click the "Preview" tab for better readability.
> Thanks for contributing to Parse Platform!
> \--\>
> 
> \- \[x\] I am not disclosing a \[vulnerability\](https://github.com/parse-community/parse-server/blob/master/SECURITY.md).
> \- \[x\] I am not just asking a \[question\](https://github.com/parse-community/.github/blob/master/SUPPORT.md).
> \- \[x\] I have searched through \[existing issues\](https://github.com/parse-community/parse-server/issues?q=is%3Aissue).
> \- \[x\] I can reproduce the issue with the \[latest version of Parse Server\](https://github.com/parse-community/parse-server/releases). 
> 
> \### Issue Description
> Can't download a text file. The file opens in a browser, I need to save it manually. 
> 
> \### Steps to reproduce
> Upload some text file. Try to download it by link.
> 
> \### Actual Outcome
> 
> 
> \### Expected Outcome
> I want to download the file immediantly. 
> 
> \### Environment
> 
> 
> Server
> \- Parse Server version: \`FILL\_THIS\_OUT\`
> \- Operating system: \`FILL\_THIS\_OUT\`
> \- Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): \`FILL\_THIS\_OUT\`
> 
> Database
> \- System (MongoDB or Postgres): \`FILL\_THIS\_OUT\`
> \- Database version: \`FILL\_THIS\_OUT\`
> \- Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): \`FILL\_THIS\_OUT\`
> 
> Client
> \- SDK (iOS, Android, JavaScript, PHP, Unity, etc): \`FILL\_THIS\_OUT\`
> \- SDK version: \`FILL\_THIS\_OUT\`
> 
> \### Logs

---

<div class="post-metadata">

**Author:** ![Manuel](https://community.parseplatform.org/user_avatar/community.parseplatform.org/manuel/32/186_2.png) [@Manuel](https://community.parseplatform.org/u/Manuel)\
**Post date:** [March 26, 2022, 2:46am UTC](https://community.parseplatform.org/t/force-downloads/2528/8 "2022-03-26T02:46:36Z")

</div>

@dblythy it seems that @brunobg’s question could also be solved with your suggested a `beforeGetFile` trigger.

~~@brunobg Do you want to open a Parse Server issue to suggest a feature for a `beforeGetFile` trigger where you can set custom HTTP headers for the file response?~~  
So there is already a FR for that it seems: [beforeGetFile trigger · Issue #6572 · parse-community/parse-server · GitHub](https://github.com/parse-community/parse-server/issues/6572)

---

<div class="post-metadata">

**Author:** ![brunobg](https://community.parseplatform.org/user_avatar/community.parseplatform.org/brunobg/32/967_2.png) [@brunobg](https://community.parseplatform.org/u/brunobg)\
**Post date:** [March 28, 2022, 8:53pm UTC](https://community.parseplatform.org/t/force-downloads/2528/9 "2022-03-28T20:53:39Z")

</div>

> [@brunobg](#):
>
> Is there a way to get access to the file adapter data given a `Parse.File` object?

Thank you for the suggestions and the FR! But what about this, any way to access the adapter directly so I can work around meanwhile?

---

<div class="post-metadata">

**Author:** ![Manuel](https://community.parseplatform.org/user_avatar/community.parseplatform.org/manuel/32/186_2.png) [@Manuel](https://community.parseplatform.org/u/Manuel)\
**Post date:** [March 28, 2022, 9:38pm UTC](https://community.parseplatform.org/t/force-downloads/2528/10 "2022-03-28T21:38:56Z")

</div>

What do you mean by file adapter data? You can access the storage adapter from within Cloud Code and maybe override the getUrl method that generates the URL, if that helps.

---

<div class="post-metadata">

**Author:** ![brunobg](https://community.parseplatform.org/user_avatar/community.parseplatform.org/brunobg/32/967_2.png) [@brunobg](https://community.parseplatform.org/u/brunobg)\
**Post date:** [March 29, 2022, 11:40am UTC](https://community.parseplatform.org/t/force-downloads/2528/11 "2022-03-29T11:40:18Z")

</div>

> [@Manuel](#):
>
> What do you mean by file adapter data?

I want to get access to the S3 data so I can access it directly, when all I have is the `Parse.File` object that I got from `myBaseObject.get('myfile')`. Here’s some pseudo code of what I want to do:

```auto
const myFile = myBaseObject.get('myfile');
const s3Url = myFile.getS3Adapter().getUrl();
const downloadUrl = s3Url + '&request-content-type="application/force-download"';

```

Thank you!

---

<div class="post-metadata">

**Author:** ![Manuel](https://community.parseplatform.org/user_avatar/community.parseplatform.org/manuel/32/186_2.png) [@Manuel](https://community.parseplatform.org/u/Manuel)\
**Post date:** [March 29, 2022, 12:41pm UTC](https://community.parseplatform.org/t/force-downloads/2528/12 "2022-03-29T12:41:36Z")

</div>

```auto
const ServerConfig = require('../node_modules/parse-server/lib/Config');
const config = ServerConfig.get(Parse.applicationId);
const adapter = config.filesController.adapter;
const url = adapter.getFileLocation(config, “example.txt”);

```
