fail to download jpg file in chrome using https connection - web

I'm creating a button, that will download a jpg file when you click it. What Im doing is that redirect to a hyperlinking to the img file and setting the content-type and content-disposition headers there using the code below
header('Content-Description: File Transfer');
header('Content-Type: image/jpeg' );
header('Content-Length: ' . filesize($fullpath));
header('Content-Disposition: attachment; filename=' . basename($filename));
readfile($fullpath);
$fullpath is the pysical location of the jpg file
it works fine in chrome IE and firefox in my develop website, which used http connection.
but when I put it the live website, which uses https connection, IE and firefox still works fine, but chrome sometimes works, sometime it will show a page with messed up strings instead of download the jpg file. I think maybe chrome didn't recognize the MIME type of the jpg file and treat it as plain text. This is pretty odd (sometime it could recognize the jpg file and download it, sometime not) . Has anyone got the same problem before or has any idea to fix this?

Related

Specifying path/filename in downloads.download() api not working in Chrome but does in Firefox

Specifying path/filename to downloading file does not work in chrome.downloads api but does work for firefox browser.downloads api.
I have a very simple call in popup.js for chrome and firefox:
chrome.downloads.download({url: address, filename: path + "/" + filename, saveAs: false});
Here's another one for Firefox:
browser.downloads.download({url: addresss, filename: path + "/" + filename, saveAs: false});
It works perfectly as expected in firefox, but no matter what, I can't ever get it to work in chrome. Even with a simple download of google's image to a different file name never works chrome but does in firefox, such as:
chrome.downloads.download({url: "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png", filname: "temp/temp.png"});
What am I doing wrong?
It's been awhile but I'll post my solution for whoever comes across this issue for their extension. It turns out that specifying a custom filename isn't working is because there are extension conflicts.
If there is another extension using the chrome.downloads API, specifically the chrome.downloads.onDeterminingFilename.addListener, which tries to specify the filename that overrides the original filename suggestion. This also happens even if the conflicting extension did not change your download options but just added a listener for onDeterminingFilename without doing any logic. This is a known chromium issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=579563. That issue has been opened since 2016 and the devs still have not addressed it.
Workaround solution: implement your own chrome.downloads.onDeterminingFilename.addListener to suggest your custom filename. Make sure that you're only capturing downloads that you started yourself but comparing the download item's id and extension id. The only caveat is that the conflicting extension will produce an error saying they could not suggest their own filename.
Firefox does not have this issue because their extension API does not have onDeterminingFilename.

How to upload an mp4 (or other video) to Imgur using the API?

I am using the Imgur API to upload images to albums, as part of a Reddit bot. However, when I try to upload MP4 files I get an error: "File type invalid (1)". Uploading the exact same MP4 file using the website works just fine.
I am using this endpoint to upload the file: POST https://api.imgur.com/3/image
https://apidocs.imgur.com/#c85c9dfc-7487-4de2-9ecd-66f727cf3139
The above comment is no longer correct -- You can indeed upload an MP4 using Imgur API
import requests
url = "https://api.imgur.com/3/upload"
payload = {'album': 'ALBUMID',
'type': 'file',
'disable_audio': '0'}
files = [
('video', open('/path/to/Video.mp4','rb'))
]
headers = {
'Authorization': 'Bearer BEARERTOKENHERE'
}
response = requests.request("POST", url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))
The above works for me and uploads successfully. Something to note though, I have not figured out how to make the upload tied to my account, or within a specific album. It seems to be ignoring the album_id field. In other words, despite using the Bearer token, it appears to be navigating the API "anonymously".
From the imgur Help site, located here and last updated 2 months ago:
https://help.imgur.com/hc/en-us/articles/115000083326-What-files-can-I-upload-What-is-the-size-limit-
File Types
If you need help learning how to upload on Imgur, check out this help
article. You can upload any of the following files: JPEG, PNG, GIF, APNG, TIFF, MOV (desktop website only), MP4 (desktop website
only)
Imgur doesn't currently support uploads in the following
formats: WEBM GIFV
Explicitly, MP4s are only currently supported as uploaded manually via the website directly.
Unfortunately, that means imgur does not support MP4 types through any method other than the Desktop site at this current time.
I agree with a comment above. Now it is works great. Even you can upload the video without authorization. Just using a POST method https://api.imgur.com/3/upload. Pass a video file in body with image key. That's all.
Example in Postman

How can i give link to download(not open) pdf file in reactjs

this is my code which i am writing in render method, which works fine, but instead of downloading this file it's opening in browser.
download
How can i give a link in react to force download a file, file which is coming from external server.
HTML5
<a download href="file.pdf">Download PDF</a>
Suppose you have a variable names as "link" in which the link is stored. So you can do,
<a href={`${link}`} type="application/pdf; download='some_pdf_name'>Download</a>

Changing video content type (mime type) in CDN in drupal 7

I am using media module to save media in CDN. To play videos, we are using jwplayer in Drupal 7. Jwplayer throws error in IE, If video is not of content type [mime type] *video/mp4*. I have changed the existing CDN videos mime type from application/octet-stream to video/mp4.
Now whatever mp4 videos are being uploaded/saved to cdn should only be of video/mp4 mime type but when I upload mp4 videos in media module it is saved in CDN with mime type application/octet-stream, How do I change the uploaded mime type [content type] to video/mp4.
CDN module code
function CDNtransfer_content($source,$destination) {
$s3=_CDN_transfer_load();
$up_bucket="cdn.example.com";
$uploadOk=null;
$expires=date('D, d M Y H:i:s O', strtotime('+10 year'));
$headers=array('Content-Type' => 'video/mp4', 'Expires' => $expires);
if($destination)
{
$up_state=$s3->putObject($up_bucket, $destination, $source, 'true', $headers);
if($s3->objectExists($up_bucket, $destination)) {
$uploadOk =1;
}
else {
$uploadOk ="Error: File Not Uploaded Correctly. Please try again.";
}
}
return $uploadOk;
}
Even setting the above header does not seem to work !!! not sure why ??
We are using s3 php sdk 2 aws stand alone class with our custom module in drupal.
How do I change mime type[content type] to video/mp4 in media module, Drupal 7, when mp4 video are being uploaded.
A MIME-TYPE is a server side setting. You can ask your hosting provider to add the MP4 MIME-TYPE for you.
Or, you can add a .htaccess file to the directory where you uploads are stored.
A sample .htaccess file that adds the MP4 MIME-TYPE is:
<IfModule mod_rewrite.c>
AddType video/mp4 .mp4
</IfModule>
If you are not able to add the MIME TYPE properly, one work around you can use is to force the JW Player to run as Flash, which is less strict about MIME-TYPEs, by adding this line, to your player's embed code:
primary: 'flash',
Let me know if this helps!
Found the Answer :
1) As Ethan said "A MIME-TYPE is a server side setting. You can ask your hosting provider to add the MP4 MIME-TYPE for you.
Or, you can add a .htaccess file to the directory where you uploads are stored".
A sample .htaccess file that adds the MP4 MIME-TYPE is:
<IfModule mod_rewrite.c>
AddType video/mp4 .mp4
</IfModule>"
Source : Need to Change Video Content Type to video/mp4 so it plays in IE
But this did not work for me for some reason
2) I did the change in my core class file which i was using in drupal module for CDN upload
I had made a change in my class.s3.php file -> in mime_type[] array and also, cross checked with putObject() function.
**
Setting of mime type is always done in coding side and not in AWS S3
bucket, We need to use AWS PHP Class file or sdk to do the
manipulation in mime type or make the necessary changes in core class
file (eg. class.s3.php )
**
For details check here find-mime-type-of-file-or-url-using-php-for-all-file-format
Second Answer has worked for me :)

pdf download problem

I just want to add a link for pdf file.
But when i click on the link then pdf file open in the browser,
But i want that user prompt for to save or open the pdf file.
Thanks in advance.
If you can add a header in the response from the server:
Content-Disposition: attachment; filename="<your-file-name>"

Resources