Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uploading MP3 file to Firebase Storage ends up being a video/mp3 file

Im trying to save an audio in the new Firebase Storage option, the audio is set as a .mp3 file and the uploaded to Firebase via this code : UploadTask uploadAudio = storageRef.putFile(audioUri); The problem is that the audio is stored as a video/mp4 file, and because of that the MediaPlayer does not reproduce it as an audio, how can I fix this?

like image 909
Andrey Avatar asked Jul 10 '16 20:07

Andrey


People also ask

Can Firebase store MP3?

You can explicitly specify metadata when you upload the file to Firebase. If you specify setContentType("audio/mpeg") it should map the file to an MP3 correctly.

Can we upload video to Firebase storage?

Cloud Storage for Firebase allows you to quickly and easily upload files to a Cloud Storage bucket provided and managed by Firebase.


2 Answers

Moving comment to answer:

You can explicitly specify metadata when you upload the file to Firebase. If you specify setContentType("audio/mpeg") it should map the file to an MP3 correctly.

like image 159
Mike McDonald Avatar answered Oct 03 '22 02:10

Mike McDonald


 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))")
        }
        
    }
    
}
like image 35
Rabie Avatar answered Oct 03 '22 01:10

Rabie