HI,
I currently upload a txt data file to backndless for each user. Is it possible to convert this to a wave file and then save it in the cloud? or do I need to upload a new file?
Best,
F
HI,
I currently upload a txt data file to backndless for each user. Is it possible to convert this to a wave file and then save it in the cloud? or do I need to upload a new file?
Best,
F
Hello,
you can rename it with api https://backendless.com/docs/android/doc.html#file_renaming_a_file_directory
ok what if I want to upload a data file as a wave file?
My current code is :
class func uploadData(data: [Float]) -> Promise<BackendlessFile> {
let rawData = String(describing: data).data(using: .utf8)!
let fileName = "\(currentUser.firstName)-\(currentUser.lastName)-\(Date().timeIntervalSince1970)"
return Promise { (fulfill, reject) in
backendless.fileService.upload("screams/\(fileName).txt",
content: rawData,
response: { file in
fulfill(file!)
},
error: { fault in
reject(fault!)
})
}
}
Why would you want to do that? I’m not sure you can convert wave file to text and then back without data corruption.
I wont be converting it back…if I can upload it as a wave file I wont change it again
You can upload it as pure byte array with a name ‘yourfile.wav’. You don’t need to convert it to string. Just use the saveFile method: https://backendless.com/docs/js/doc.html#file_save_files_from_byte_arrays
Thank you but thats javascript, Is there a similar function in swift?
Thank you. I have the following code. but the uploaded file is not playable:
class func uploadData(data: [Float]) -> Promise<BackendlessFile> {
let rawData = NSData(bytes: data, length: data.count*MemoryLayout<Float>.size)
//String(describing: data).data(using: .utf8)!
let fileName = "\(currentUser.firstName)-\(currentUser.lastName)-\(Date().year)-\(Date().month)-\(Date().day)"
return Promise { (fulfill, reject) in
backendless.fileService.saveFile("screams/\(fileName).wav",
content: rawData as Data!,
response: { file in
fulfill(file!)
},
error: { fault in
reject(fault!)
})
}
}
I suppose you are implying that the bytes were not saved correctly.
Could you verify that the file created as a result of the upload contains exactly the same bytes you send in the API call?
Regards,
Mark
Hi Mark,
Not exactly. I don’t know much about audio encoding. I changed the code to:
class func uploadData(data: [Float]) -> Promise<BackendlessFile> {
let rawData = String(describing: data).data(using: .utf8)!
let fileName = "\(currentUser.firstName)-\(currentUser.lastName)-\(Date().year)-\(Date().month)-\(Date().day)"
return Promise { (fulfill, reject) in
backendless.fileService.saveFile("screams/\(fileName).txt",
content: rawData,
response: { file in
fulfill(file!)
},
error: { fault in
reject(fault!)
})
}
}
…this uploads a txt file with an array of numbers as expected. Are you sure we can just change the name of the file?
Best,
Feras A.
Hi Feras,
Backendless saves the bytes you send the same way whether you specify .txt or .wav. The code which persists the files does not apply any kind of different encoding.
If the file does not play, the first thing you should do is to check whether the saved bytes are the same as the ones you sent. Any HEX comparison tool should be able to help you with that.
IF the content is the same AND the file does not play, then the problem is with the bytes you sent. Otherwise, if the content is different, please let us know and we will be happy to investigate why it was not the persisted as expected.
Regards,
Mark
I believe the content is the same. therefore I am preparing it in the wrong manner.
Thanks
F
Thanks for letting us know. I will close this topic with the resolution of “Works as designed”. Please let us know if we can be of any help.
Regards,
Mark