Content Disposition header in File Download URL
Hi ,
Any one please help me to achieve this. I am uploading files using platform App user (through JWT Oauth2), I am able to upload and download the file. But here I have scenario like, if the file is uploaded as 'TestFile.jpg' then I want to download it as 'sample.jpg'. I have tried to add content-disposition header for my Download method, but file is getting downloded with actual file name Could you please help me for this.
Below is the code that I am trying,
HttpRequest req = NEW HTTPRequest ();
req.setMethod ('GET');
req.setEndpoint ('https://api.box.com/2.0/files/***number removed for privacy***855/content');
req.setHeader ('Authorization', 'Bearer '+accessToken);
req.setHeader ('content-disposition', 'attachment; filename="test.png"');
HTTP http = NEW HTTP ();
HTTPResponse res = http.send (req);
String downloadURL = '';
downloadURL = res.getHeader('Location');
Thanks,
Srikanth
-
Content-Disposition is a header that is typically sent from servers to clients. See https://tools.ietf.org/html/rfc6266#section-3 . It is not something that the API accepts from the client request.
If your client wants to use a different name, it is under no obligation to use the true filename / the filename in the response Content-Disposition header. It can do whatever it pleases with the raw file content.
-
I'm not certain what language you're using (Java?), but from the code sample you provided, I can see that you are manually calling the API, and you aren't using an SDK to download the file.
Thus, you can download the file to a different location using whatever utilities are built into your language. That is entirely outside of the domain of Box.
If you are using Java, here are some suggestions: http://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java . When specifying the target location on your file system, choose whatever name and location that you wish.
サインインしてコメントを残してください。
コメント
3件のコメント