Rackspace cloud files return "application/unknown" as mime-type when uploaded with Jclouds - mime-types

Basically I have this code which uploads javascripts and other content to Rackspace using Jclouds:
SwiftObject obj = cloudFilesClient.newSwiftObject();
obj.getInfo().setName(name);
obj.getInfo().setContentType(contentType);
obj.setPayload(payloadFile);
cloudFilesClient.putObject(container, obj);
I noticed that Chrome complains about scripts being transferred with text/plain and so set out to investigate. curl -I report instead: Content-Type: application/unknown.
I've Googled a lot and tried to find some clues, and I've tried:
not setting content type at all
setting empty string (found some rumour about that somewhere)
setting to application/javascript (correct)
setting to text/javascript (wrong, but common)
obj.getAllHeaders().put("Content-Type", contentType);
When we used to upload with basic HTTP before, this just worked without setting anything manually at all.

Finally finally managed to figure it out by digging in the source code - this works:
FilePayload payload = new FilePayload(uploadableFile.localPath.toFile());
payload.getContentMetadata().setContentType(uploadableFile.contentType);
obj.setPayload(payload);
In case anyone else is looking for this in the future, posting Q&A.

Related

Form Data: wrong Content-Type for .p7m files

I need to save a file with correct MimeType for .p7m files (application/pkcs7-mime) via form upload to the server.
In the request I noticed that Content-Type is wrong:
------WebKitFormBoundaryaglEgtBJlb65v7d5
Content-Disposition: form-data; name="file0"; filename="getmymimeplease.p7m"
Content-Type: application/pkcs7
it should be:
Content-Type: application/pkcs7-mime
How is possible that the '-mime' part is missing (or truncated) ?
This is usually controlled by OS and/or Browser. On windows, this is set in the registry, in HKEY_CLASSES_ROOT\.<fileextension>, e.g. HKEY_CLASSES_ROOT\.p7m, in the Field Content Type:
So in the end, this is controlled by the client. So if there are several possible mime types for the same extension, you need to cover that in your server code (accept or decline, convert to your default or not)

Copy static files from one Jekyll post to published site

I would like to copy any static file (image, PDF, etc.) found in a post folder inside _posts to the folder in which the HTML version of the post will be, inside _site.
Let's say I have this structure:
_posts/
2016/
06/
09-so-long-cloudflare/
2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
cloudflare-logo.png
performance-report-sample.pdf
My Jekyll settings for permalinks are:
# Permalinks
permalink: /:year/:month/:day/:title/
I would like to generate the site like this:
2016/
06/
09/
so-long-cloudflare-and-thanks-for-all-the-fissh/
index.html
cloudflare-logo.png
performance-report-sample.pdf
I've found this plugin that should do this, but I can't make it work. I get this error:
jekyll 3.1.6 | Error: undefined method `name' for #<Jekyll::Document:0x007fb7a0892b50>
Any idea?
Thanks!
Well, despite having no Ruby knowledge, I managed to build a plugin out of this old Gist! \o/
https://nhoizey.github.io/jekyll_post_files/
I hope this will help people with the same needs.

Google App Engine and ttf font not working

I've got a small problem where google app engine is complaining about my ttf file. This is what it says:
Could not guess mimetype for css/fonts/Pacifico.ttf. Using application/octet-stream.
Now I've followed this link and changed my yaml file appropriately (or so I think):
- url: /css/fonts/(.*\.ttf)
static_files: css/fonts/\1
upload: css/fonts/(.*\.ttf)
mime_type: application/x-font-ttf
But when I do this i get the following:
appcfg.py: error: Error parsing C:\Users\Roberto\Desktop\bootstrap\app.yaml: mapping values are not allowed here
in "C:\Users\Roberto\Desktop\bootstrap\app.yaml", line 25, column 17.
2014-01-16 23:22:16 (Process exited with code 2)
Any help in this matter?
I have done a test with glyphicons-halflings-regular.ttf from the Bootstrap project with the same app.yaml handler that you use (save for the indentation change as per the comments) and can verify that it works as expected:
This leads me to believe that you may using an older version of the GAE SDK (I use 1.8.8) or something else is wrong with your installation.
You can try this: appcfg.py uses python's mimetypes module to guess the type from the file extension so in any case, you should be able to solve the issue by adding the application/x-font-ttf mime type to your OS.
You're on Windows so you need to edit your registry and add a application/x-font-ttf key to HKEY_CLASSES_ROOT\MIME\Database\Content Type and add a string value called Extension with the value .ttf under the new key.
Extended procedure for adding the mimetype to Windows
Open the registry editor: Hit Winkey + R and type regedit, hit Enter
Navigate through the registry to the desired location: open HKEY_CLASSES_ROOT, inside it open MIME, inside that open Database and inside that open Content Type. It's like a folder structure.
Right click on Content Type and select New > Key, give it the name application/x-font-ttf.
Right click on the key you just created and select New > String Value. give it the name Extension.
Double click on the value you just created and assign it the Value data .ttf, hit OK.
Exit regedit and you're done!
Final none: I don't think it can be anything to do with the file itself, because the mimetypes module uses only the file extension to work out the MIME type. Unless there is some crazy unprintable character in the filename. You could try using the glyphicons-halflings-regular font I linked to to eliminate this possibility.

URL returned non 200 response code

I am Indexing Documents by using SolrPhpClient library. while making POST request by Solr using extract function reply with
URL http://localhost/moodledemo/pluginfile.php/99/course/overviewfiles/pre bio- data.docx returned non 200 response code".
It happens only if the file name include space. if the filename don't have any space it goes well.
I don't conclude why it returns non 200 response with files that have space in their names. while accessing the same path works in browser.
Using rawurlencode() Solved the Issue..
may be the jetty server was responding with non 200 response code with the filename:-
How are you.doc
Using rawurlencode()
How%20are%20you.doc
Thanks :)

tcpdf generates .html document in safari and opera

I am using tcpdf with Cakephp. The PDFs are downloaded good in Linux but when it comes to Mac for Opera and Safari it add .html ectension to it.
I also noticed that even if it downloads as PDF document in FireFox and Google Chrome, the Pop-up to save as reads it as "HTML document" but save as PDF. PLease help me with this.
Try to modify headers, like:
header("Content-Description: File Transfer");
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file_name));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Cache-Control: private", false); // required for certain browsers
header('Pragma: public');
header('Content-Length: ' . filesize($file_name));
Hope it works. :)
It seems like Mac and Safari are more strict when it comes to mime types, and always obeys the content type set in your scripts. So if the Content type is being set to text/html, Safari will expect it to be a HTML document and add the html extension. Firefox and Chrome are using this content-type header to present the file type (HTML document), but does not change the filename so it saves as a PDF.
As you are using CakePHP, it's a good idea to use the built in file response in your Controller:
$this->response->file($path,array('download' => true, 'name' => $filename));
return $this->response;
This will correctly set the headers you need for most files. See here for docs: http://book.cakephp.org/2.0/en/controllers/request-response.html#sending-files
Be warned, CakePHP might not know the mimetype of some files, and will default to text/html. Then you'll get the same problem in Safari. It's a good idea to test and if you see this happening, set the mime types yourself (BEFORE setting the file):
$ext = pathinfo($filename, PATHINFO_EXTENSION);
switch ($ext) {
case 'dotx':
$this->response->type('application/vnd.openxmlformats-officedocument.wordprocessingml.template');
break;
}
$this->response->file($path,array('download' => true, 'name' => $filename));
return $this->response;
I found by adding
$this->response->type('application/pdf');
to the view file and by updating to the latest version of the TCPDF vendor files it resolved the same issue for us (as well as other display issues).
In your controller simply add this
$this->response->header(array('Content-type: application/pdf'));
$this->response->type('pdf');
By adding this same issue is solved to me.

Resources