Django: How to download file from S3Having Django serve downloadable filesHow to combine 2 or more querysets in a Django view?Does Django scale?How to debug in Django, the good way?Programmatically saving image to Django ImageFieldDownloading a csv file in djangoNeed a minimal Django file upload exampleHow to check Django versiondifferentiate null=True, blank=True in djangoDownloading an entire S3 bucket?Downloading a file from an s3 Bucket to the USERS computer
Is Newton's third law really correct?
How can a clan of females defend themselves in the ancient world against wandering bands?
First occurrence in the Sixers sequence
Is there any way to revive my Sim?
Leaving job close to major deadlines
How can I prevent a user from copying files on another hard drive?
Synaptic Static - when to roll the d6?
What preparations would Hubble have needed to return in a Shuttle?
How to compute the inverse of an operation in Q#?
What is the maximum that Player 1 can win?
What is that ceiling compartment of a Boeing 737?
Definition of 'vrit'
Can a character learn spells from someone else's spellbook and then sell it?
"Prove that ∂A is closed given ∂A = Cl(A) − Int(A)"
I have found ports on my Samsung smart tv running a display service. What can I do with it?
Why are there no file insertion syscalls
Why is Havana covered in 5-digit numbers in Our Man in Havana?
Scaling an object to change its key
Why do you need to heat the pan before heating the olive oil?
Name for a function whose effect is canceled by another function?
Counterfeit checks were created for my account. How does this type of fraud work?
Can the pre-order traversal of two different trees be the same even though they are different?
In the US, can a former president run again?
Bent arrow under a node
Django: How to download file from S3
Having Django serve downloadable filesHow to combine 2 or more querysets in a Django view?Does Django scale?How to debug in Django, the good way?Programmatically saving image to Django ImageFieldDownloading a csv file in djangoNeed a minimal Django file upload exampleHow to check Django versiondifferentiate null=True, blank=True in djangoDownloading an entire S3 bucket?Downloading a file from an s3 Bucket to the USERS computer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
What I want to do is to download file from Amazon S3. I've been looking up the ways to do it but it didn't work well. I saw this question and used one of the answer's code but it didn't work so I am trying to do other way.
What I did is like this.
html
<a href="#" download=" file.file.url "> file.filename </a>
when I click the filename, it actually starts downloading but the file doesn't work. It says we don't support the file type.
I think it's because the path is wrong. When I inspect element on browser, the path looks correct but when I download the file, the file name is like https__...
not https://
How can I fix this? What is the cause?
I'm currently checking if it works on local.
Update
my current code
I ended up creating a view to download a file but it still doesn't work even on production. The content of the file is always empty. For image file, it cannot be opened.
def download_file(request, file_pk):
file = get_object_or_404(File, pk=file_pk)
name = file.file.name
path_to_file = "https://%s/media/%s" % (settings.AWS_S3_CUSTOM_DOMAINm name)
resp = HttpResponse(content_type='application/force-download')
resp['Content-Disposition'] = "attachment; filename=%s" % name
resp['X-Sendfile'] = path_to_file
return resp
django amazon-s3
add a comment |
What I want to do is to download file from Amazon S3. I've been looking up the ways to do it but it didn't work well. I saw this question and used one of the answer's code but it didn't work so I am trying to do other way.
What I did is like this.
html
<a href="#" download=" file.file.url "> file.filename </a>
when I click the filename, it actually starts downloading but the file doesn't work. It says we don't support the file type.
I think it's because the path is wrong. When I inspect element on browser, the path looks correct but when I download the file, the file name is like https__...
not https://
How can I fix this? What is the cause?
I'm currently checking if it works on local.
Update
my current code
I ended up creating a view to download a file but it still doesn't work even on production. The content of the file is always empty. For image file, it cannot be opened.
def download_file(request, file_pk):
file = get_object_or_404(File, pk=file_pk)
name = file.file.name
path_to_file = "https://%s/media/%s" % (settings.AWS_S3_CUSTOM_DOMAINm name)
resp = HttpResponse(content_type='application/force-download')
resp['Content-Disposition'] = "attachment; filename=%s" % name
resp['X-Sendfile'] = path_to_file
return resp
django amazon-s3
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03
add a comment |
What I want to do is to download file from Amazon S3. I've been looking up the ways to do it but it didn't work well. I saw this question and used one of the answer's code but it didn't work so I am trying to do other way.
What I did is like this.
html
<a href="#" download=" file.file.url "> file.filename </a>
when I click the filename, it actually starts downloading but the file doesn't work. It says we don't support the file type.
I think it's because the path is wrong. When I inspect element on browser, the path looks correct but when I download the file, the file name is like https__...
not https://
How can I fix this? What is the cause?
I'm currently checking if it works on local.
Update
my current code
I ended up creating a view to download a file but it still doesn't work even on production. The content of the file is always empty. For image file, it cannot be opened.
def download_file(request, file_pk):
file = get_object_or_404(File, pk=file_pk)
name = file.file.name
path_to_file = "https://%s/media/%s" % (settings.AWS_S3_CUSTOM_DOMAINm name)
resp = HttpResponse(content_type='application/force-download')
resp['Content-Disposition'] = "attachment; filename=%s" % name
resp['X-Sendfile'] = path_to_file
return resp
django amazon-s3
What I want to do is to download file from Amazon S3. I've been looking up the ways to do it but it didn't work well. I saw this question and used one of the answer's code but it didn't work so I am trying to do other way.
What I did is like this.
html
<a href="#" download=" file.file.url "> file.filename </a>
when I click the filename, it actually starts downloading but the file doesn't work. It says we don't support the file type.
I think it's because the path is wrong. When I inspect element on browser, the path looks correct but when I download the file, the file name is like https__...
not https://
How can I fix this? What is the cause?
I'm currently checking if it works on local.
Update
my current code
I ended up creating a view to download a file but it still doesn't work even on production. The content of the file is always empty. For image file, it cannot be opened.
def download_file(request, file_pk):
file = get_object_or_404(File, pk=file_pk)
name = file.file.name
path_to_file = "https://%s/media/%s" % (settings.AWS_S3_CUSTOM_DOMAINm name)
resp = HttpResponse(content_type='application/force-download')
resp['Content-Disposition'] = "attachment; filename=%s" % name
resp['X-Sendfile'] = path_to_file
return resp
django amazon-s3
django amazon-s3
edited Mar 25 at 5:59
Ooto
asked Mar 25 at 4:13
OotoOoto
13718
13718
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03
add a comment |
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03
add a comment |
1 Answer
1
active
oldest
votes
That's because of the metadata setting of your file stored in S3.
Can you try to change the metadata of the file you want to download?
The step is below
In your S3 storage, choose the file and select [properties] -> [metadata]
Then, add new metadata as the "Content-Deposition" key and "attachment" value.
The link below is very useful to understand.
https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3
Then, you need to change the HTML like this.
<a href=" file.file.url " download="filename.extension"> file.filename </a>
I'm not sure it works for any type of files. But it worked when I developed a system that downloads a jpeg file.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331188%2fdjango-how-to-download-file-from-s3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That's because of the metadata setting of your file stored in S3.
Can you try to change the metadata of the file you want to download?
The step is below
In your S3 storage, choose the file and select [properties] -> [metadata]
Then, add new metadata as the "Content-Deposition" key and "attachment" value.
The link below is very useful to understand.
https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3
Then, you need to change the HTML like this.
<a href=" file.file.url " download="filename.extension"> file.filename </a>
I'm not sure it works for any type of files. But it worked when I developed a system that downloads a jpeg file.
add a comment |
That's because of the metadata setting of your file stored in S3.
Can you try to change the metadata of the file you want to download?
The step is below
In your S3 storage, choose the file and select [properties] -> [metadata]
Then, add new metadata as the "Content-Deposition" key and "attachment" value.
The link below is very useful to understand.
https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3
Then, you need to change the HTML like this.
<a href=" file.file.url " download="filename.extension"> file.filename </a>
I'm not sure it works for any type of files. But it worked when I developed a system that downloads a jpeg file.
add a comment |
That's because of the metadata setting of your file stored in S3.
Can you try to change the metadata of the file you want to download?
The step is below
In your S3 storage, choose the file and select [properties] -> [metadata]
Then, add new metadata as the "Content-Deposition" key and "attachment" value.
The link below is very useful to understand.
https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3
Then, you need to change the HTML like this.
<a href=" file.file.url " download="filename.extension"> file.filename </a>
I'm not sure it works for any type of files. But it worked when I developed a system that downloads a jpeg file.
That's because of the metadata setting of your file stored in S3.
Can you try to change the metadata of the file you want to download?
The step is below
In your S3 storage, choose the file and select [properties] -> [metadata]
Then, add new metadata as the "Content-Deposition" key and "attachment" value.
The link below is very useful to understand.
https://docs.easydigitaldownloads.com/article/1172-how-do-i-force-files-to-download-in-amazon-s3
Then, you need to change the HTML like this.
<a href=" file.file.url " download="filename.extension"> file.filename </a>
I'm not sure it works for any type of files. But it worked when I developed a system that downloads a jpeg file.
edited Mar 25 at 6:18
answered Mar 25 at 6:10
Ryohei ImaizumiRyohei Imaizumi
864
864
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55331188%2fdjango-how-to-download-file-from-s3%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
is it possible to download directly on browser?
– JPG
Mar 25 at 4:30
@JPG That's what I want to do. It starts downloading but the content is empty.
– Ooto
Mar 25 at 4:34
can you check your s3 policies are open ??
– Nakul Narayanan
Mar 25 at 6:03