我正在尝试将声音文件从 ngCordova 的 $cordovaCapture 服务上传到 UploadCare。uploadcare.fileFrom('object') 不断失败,并出现“上传”错误。我有公钥集。我可以通过发送文件并标记并访问 document.getElementById('fileTag').files[0] 来上传文件。
$cordovaCapture.captureAudio()
.then(function (audioData) {
return uploadcare.fileFrom('object', audioData[0])
.done(function (fileInfo) {
console.log(fileInfo);
}).fail(function (err) {
console.log(err);
})
})
audioData[0] 对象看起来像这样
MediaFile {
end:0
fullPath:"file:/storage/emulated/0/Sounds/Voice%20002.m4a"
lastModified:null
lastModifiedDate:1481324751000
localURL:"cdvfile://localhost/sdcard/Sounds/Voice%20002.m4a"
name:"Voice 002.m4a"
size:49227
start:0
type:"audio/mpeg"
} __proto__:File
我认为问题可能是该对象是 MediaFile 而不是 File 但我可以使用一些帮助将一个转换为另一个。
FileEntry
filesystem:FileSystem
fullPath:"/Sounds/Voice 002.m4a"
isDirectory:false
isFile:true
name:"Voice 002.m4a"
nativeURL:"file:///storage/emulated/0/Sounds/Voice%20002.m4a"
__proto__:Entry
File
end:49227
lastModified:1481324751000
lastModifiedDate:1481324751000
localURL:"cdvfile://localhost/sdcard/Sounds/Voice%20002.m4a"
name:"Voice 002.m4a"
size:49227
start:0
type:"audio/mpeg"
__proto__:Object
使用window.resolveLocalFileSystemUrl()你最终得到了上面的FileEntry对象,它给出了上面的File对象,但 uploadcare 仍然失败并出现“上传”错误。