gpt4 book ai didi

javascript - 从 Cordova MediaFire 上传护理文件

转载 作者:行者123 更新时间:2023-12-03 05:16:58 29 4
gpt4 key购买 nike

我正在尝试将声音文件从 ngCordova 的 $cordovaCapture 服务上传到 UploadCare。 uploadcare.fileFrom('object') 不断失败并出现“upload”错误。我已经设置了公钥。我可以通过发送文件并标记并访问 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仍然失败,并显示“上传”错误。

最佳答案

使用 ngCordova $cordovaFileTransfer() 您可以将音频文件发送到 uploadcare。

        var fileName = filePath.split('/').pop();
var uploadcareOptions = {
fileKey: "file",
fileName: fileName,
chunkedMode: false,
mimeType: 'audio/mp4',
params: {
"UPLOADCARE_PUB_KEY": "upload-care-public-key",
"UPLOADCARE_STORE": 'auto',
fileName: fileName
}
};
return $cordovaFileTransfer.upload('https://upload.uploadcare.com/base/', filePath, uploadcareOptions)

重要的是在发送文件时指定 mime 类型,否则 uploadcare 会假设它是图像。

关于javascript - 从 Cordova MediaFire 上传护理文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41559091/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com