Skip to content

Commit

Permalink
ファイルアップロード時のMIME Type判定を正確に
Browse files Browse the repository at this point in the history
  • Loading branch information
to committed Jan 12, 2010
1 parent 85c59c3 commit 0a91cc4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
1 change: 1 addition & 0 deletions xpi/chrome/content/library/00_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var FaviconService = getService('/browser/favicon-service;1', Ci.nsIFavicon
var StyleSheetService = getService('/content/style-sheet-service;1', Ci.nsIStyleSheetService);
var FuelApplication = getService('/fuel/application;1', Ci.fuelIApplication);
var PrefService = getService('/preferences-service;1');
var MIMEService = getService('/mime;1', Ci.nsIMIMEService);


var PrefBranch =
Expand Down
17 changes: 5 additions & 12 deletions xpi/chrome/content/library/01_utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ function request(url, opts){
]);
} else {
if(value.file instanceof IFile){
value.contentType = value.contentType || guessContentType(value.file);
value.contentType = value.contentType || getMimeType(value.file);
value.fileName = value.file.leafName;
value.file = IOService.newChannelFromURI(createURI(value.file)).open();
}
Expand Down Expand Up @@ -617,17 +617,10 @@ function request(url, opts){
return d;
}

// FIXME: Firefox内の実装を探す
function guessContentType(ext){
if(ext instanceof IFile)
ext = ext.leafName.split('.').pop();

return {
mp3 : 'audio/mpeg',
m4a : 'audio/mp4',
png : 'image/png',
jpg : 'image/jpeg',
}[ext];
function getMimeType(file){
return (file instanceof IFile)?
MIMEService.getTypeFromFile(file) :
MIMEService.getTypeFromExtension(file)
}

// ----[MochiKit]-------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions xpi/chrome/content/library/20_model.js
Original file line number Diff line number Diff line change
Expand Up @@ -2252,13 +2252,7 @@ models.register({
return request(this.URL + '/tracks', {
redirectionLimit : 0,
sendContent : {
'track_files[]' : {
file : file,
contentType : {
mp3 : 'audio/mpeg',
m4a : 'audio/mp4'
}[file.leafName.split('.').pop()],
},
'track_files[]' : file,
},
});
},
Expand Down

0 comments on commit 0a91cc4

Please sign in to comment.