我正在开发混合移动应用程序。如何从Cordova File Transfer插件获取mimeType?
在我们选择或上传文件时,我们需要从文件中获取mimeType。
我正在使用Apache FileTransfer。
window.resolveLocalFileSystemURL(fileURI所,resolveOnSuccess,resolveOnFail)
我正在开发混合移动应用程序。如何从Cordova File Transfer插件获取mimeType?
在我们选择或上传文件时,我们需要从文件中获取mimeType。
我正在使用Apache FileTransfer。
window.resolveLocalFileSystemURL(fileURI所,resolveOnSuccess,resolveOnFail)
file-transfer
不暴露mime类型和其他FileUploadOptions PARAMS。
仅在Windows plugin code上载支持Mimetype自动检测。
和here is a Jira ticket for this feature CB-5946 - 它也有一些关于Android实现的建议。
你可以从cordova File插件中获取它。
$cordovaFile.checkFile(uri, '')
.then(function(entry) {
// success
var name = entry.name;
entry.file(function(data) {
// get mime type
var mime = data.type;
alert(mime);
})
}, function(error) {
// error
// show toast
});
在角2我用这个:
export class Plugins {
albums = {
open() : Promise<any> {
return ImagePicker.getPictures({
quality: 100,
maximumImagesCount: 1,
}).then((imgUrls) => {
return imgUrls;
}, (err) => {
if(err.error == "cordova_not_available") {
alert("Cordova is not available, please make sure you have your app deployed on a simulator or device");
} else {
console.log("Failed to open albums: " + err.error);
}
});
},
}
...
@Component({
templateUrl: 'build/pages/home/home.html',
directives: [UploadButton]
})
export class HomePage implements OnInit {
openAlbums =(): void => {
var $self = this;
this._plugins.albums.open().then((imgUrls) => {
imgUrls.forEach((imageUrl: string): void => {
if (imageUrl) {
window.resolveLocalFileSystemURL(imageUrl, function (entry: FileEntry) {
entry.file(file=> {
console.log('mimeType', file.type);
}, ((error:FileError) => console.log(error)));
});
}
});
}); };
resolveLocalFileSystemURL
还给过成功回调的Entry
,我不得不投以FileEntry
以访问到文件方法,该文件方法返回File
,其延伸具有MIME类型属性的Blob
。
使用Ionic和Cordova的最新版本时,文件类型没有类型参数。 –
我得到它的工作是这样的打字稿及角2:
this._File.resolveLocalFilesystemUrl(somefileUri).then((entry: Entry) => {
if (entry) {
var fileEntry = entry as FileEntry;
fileEntry.file(success => {
var mimeType = success.type;
}, error => {
// no mime type found;
});
}
});
你确定这个工程?我通过了如下的URI:'content:// com.android.providers.media.documents/document/video%3A818',它仍然没有任何返回。我每次都得到'FileError'。 – KVISH