I am using Visual C++ to implement a function that could download image from a query.
(for example http://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap
&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318
&markers=color:red%7Ccolor:red%7Clabel:C%7C40.718217,-73.998284&sensor=false)
Note that there's no image information associate with the query itself.
Now I can successfully download it, but I want to know if there is a way I can find the download image format (i.e. jpg or png, etc) and the image name?
Edit: if you try to save the image download from the above link, you can see the browser could automatically save it as staticmap and with extension png. I was wondering where the browser could get this information?
In this case the server is responding with the content type in the HTTP response headers:
Content-Type: image/png
This is the "Internet media type" or "MIME type" of the response content.
Related
I am trying to upload a file to the Shared Documents library of my SharePoint website. The files are of type PDF and HTML. I am running a Cold Fusion development environment and using CFHTTP commands to execute HTTP requests. I have been able push a POST command and a PUT command to the proper endpoints listed on this link below:
Link: https://learn.microsoft.com/en-us/graph/api/driveitem-createuploadsession?view=graph-rest-1.0#best-practices
I do not understand why but the first section that mentions the HTTP requests for creating an upload session is different than what was used in the example a little further. For my project, I am using the endpoint:
"/{variables.instance.microsoftGraphAPIURL}/drive/root:/{item-path}:/createUploadSession"
P.S. variables.instance.microsoftGraphAPIURL is a variable to a microsoft graph endpoint to our Sharepoint website
With better luck using PUT commands than POST commands for creating an Upload Session. I am able to receive an uploadURL, but the issue comes with trying to upload the file. For the file upload, I am trying to upload a file in the same directory with a file size of 114992 bytes. I keep getting "The Content-Range header length does not match the provided number of bytes." whenever I run my Put command to upload the file.
Thus, my Content-Range is "bytes 0-114991/114992" and my Content-Length is "114992". For the image below, I replaced the file with a pdf, but the original file was an HTML page at 114992 bytes. I want to use a resumable upload session to have one function for uploading image, HTML, and PDF files.
If anyone could tell me if there is an issue with my content headers or my upload session http request or anything else that is causing my issue, that would be amazing! Thank you.
Our team is building a web app that allows users to download video files. We currently host our files on AWS S3, but since our site doesn't reside on AWS, we can't use <a href="blah"> to prompt download. If we use that html element, users simply get redirected to a video player - which is fine, but Safari on mobile doesn't allow for users to download the video file via the video player.
We found that manually setting the file's content disposition to attachment on S3 works, but we have not found a way to automate that. We tried adding a content-disposition: attachment key-value pairing in our payload, which works, but adds a "User defined" meta data in the form of x-amz-meta-content-disposition, which doesn't work as the file could not be downloaded as an attachment. It seems only "System defined" works.
Has anyone ever encountered this issue before and found a workaround?
see screenshot for what I'm referencing
You can set the content disposition when the file is created.
This is done by uploading the file via a presigned url.
See https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html for details on the presigned urls.
Alternatively you can use a presigned url to return to get the file from S3 and override the content disposition header on the GET request.
Was trying to upload docx files through a golang server using MS graph API, and although I was able to upload pdfs, when I tried uploading docx files the files were being corrupted when sent over. If I upload the same file through the OneDrive website, there would be no problems.
To isolate the issue I tried making the API calls through postman using a link like:
https://graph.microsoft.com/v1.0/users/pqv2-dev-svc#novacoast.com/drives/{drive-id}/items/{item-id}:/filename.docx:/content
used a bearer token.
the additional header of Content-Type of which I have tried the values:
text/plain
application/x-www-form-urlencoded
application/vnd.openxmlformats-officedocument.wordprocessingml.document
and uploaded the file with the form-data option under the body tab but with no luck, the file always gets corrupted.
Any ideas?
[Resolved] Was sending file as form-data instead of binary!
So you can force a download by using Content-Disposition: attachment
Content-Disposition: inline is the default and should display in the browser, and it does in fact work with most files like PNG, JPG, etc.
But for some reason somehow when generating a presigned URL from S3, PDF files will always force download even if I don't use the content-disposition: attachment header.
I want to be able to make the PDF open in the browser when the browser allows it
I am using the presigned URL generate call from S3 client http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURLJavaSDK.html
Check you file's metadata and remove Content-Disposition entry from that file. and set content type according to the file type.
Like for
text file Content-Type='text/plain'
image png Content-Type='image/png'
pdf Content-Type=application/pdf
pdfxml Content-Type=application/vnd.adobe.pdfxml
If your file's Content-Type is binary/octet-stream then it will download instead of display.
Thanks
You have to set your putObject params as follows to view pdf instead of download.
params = {
Bucket: process.env.S3_BUCKET,
Key: <fileName>,
Body: <fileContent>,
ContentDisposition:"inline",
ContentType:"application/pdf"
};
You also need to set the Content-Type correctly. The browser will check the content-type value, and if it isn't something it knows how to display it will always just download the file.
You need to provide both these meta data inorder to view the file instead of download:
Content-Disposition: attachment
Content-Type: application/pdf
Can I do this through javascript or modifying the HTTP header?
http://www.example.com/downloads/*
Any files coming out of this should not be auto-download, instead, display on browser. Can I overwrite the rules set by the browser? Can I also set this limit to just this particular sub url?
Thank you.
Thanks.
What type of file are you working with?
This is used through the HTTP header. If the mime type is a certain type, the browser will decide whether to download or display it. You can also force downloading. The file type will help.
For text files, set the content-type to text/plain. For JPEGs, set it to image/jpeg, and for PNGs set it to image/png. This should overwrite any attachment values Django is setting.
You want to use the Content-Disposition header for this. It should any haggling over content-type.
http://www.ietf.org/rfc/rfc2183.txt
The default document type is declared under your server settings, not in how you link to the file. If you are under Apache try looking in httpd.conf for
DefaultType text/plain
If it says something different that may be your problem. text/plain should set all unknowns to download and be viewed in the browser as text.
EDIT:
I don't know any way of modifying this behavior through javascript as it has to be in the header of the file being downloaded.