将 MP3 文件上传到 Firebase 存储最终成为 video/mp3 文件
Uploading MP3 file to Firebase Storage ends up being a video/mp3 file
我正在尝试在新的 Firebase 存储选项中保存音频,音频被设置为 .mp3 文件并通过以下代码上传到 Firebase:UploadTask uploadAudio = storageRef.putFile(audioUri);
问题是音频存储为 video/mp4 文件,因此 MediaPlayer 不会将其再现为音频,我该如何解决这个问题?
移动评论回答:
您可以明确 specify metadata when you upload the file 到 Firebase。如果您指定 setContentType("audio/mpeg")
它应该将文件正确映射到 MP3。
class func uploadAudios(data : Data,completion : @escaping (_ succus : String )->Void){
var url = ""
let storage = Storage.storage()
// Create file metadata including the content type
let metadata = StorageMetadata()
metadata.contentType = "audio/mpeg"
let uploadRef = storage.reference().child("audios/\(UUID().uuidString).mp3")
uploadRef.putData(data, metadata: metadata) { metadata,
error in
if error == nil {
print("successfully uploaded Audio")
url = (metadata?.downloadURL()?.absoluteString)!
print("AhmedRabie \(url)")
completion(url)
}
else {
print("UploadError \(String(describing: error))")
}
}
}
我正在尝试在新的 Firebase 存储选项中保存音频,音频被设置为 .mp3 文件并通过以下代码上传到 Firebase:UploadTask uploadAudio = storageRef.putFile(audioUri);
问题是音频存储为 video/mp4 文件,因此 MediaPlayer 不会将其再现为音频,我该如何解决这个问题?
移动评论回答:
您可以明确 specify metadata when you upload the file 到 Firebase。如果您指定 setContentType("audio/mpeg")
它应该将文件正确映射到 MP3。
class func uploadAudios(data : Data,completion : @escaping (_ succus : String )->Void){
var url = ""
let storage = Storage.storage()
// Create file metadata including the content type
let metadata = StorageMetadata()
metadata.contentType = "audio/mpeg"
let uploadRef = storage.reference().child("audios/\(UUID().uuidString).mp3")
uploadRef.putData(data, metadata: metadata) { metadata,
error in
if error == nil {
print("successfully uploaded Audio")
url = (metadata?.downloadURL()?.absoluteString)!
print("AhmedRabie \(url)")
completion(url)
}
else {
print("UploadError \(String(describing: error))")
}
}
}