Last post Jun 03, 2018 09:01 PM by DA924
Contributor
6396 Points
2061 Posts
Apr 11, 2018 05:29 AM|Primillo|LINK
Hi Folks
How to save a blob generated in the client side with javascript to SQL (varbinary MAX)
I got a long string in the client side in a HiddenField value:
data:audio/wav;base64, ...
I am getting this error "Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."
Any better way to save audio from mobile device web page using recorder.js
Best Regards
4873 Points
4123 Posts
Apr 11, 2018 05:43 AM|DA924|LINK
Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
I would say that you will have to convert the nvarchar data to binary data before trying to save it without doing a conversion at the database level.
Jun 03, 2018 06:54 PM|Primillo|LINK
I found a solution!
var audd = reader.result; audd = audd.replace("data:audio/wav;base64,", ""); $.ajax({ type: 'POST', url: 'save-audio.aspx/UploadAudio', data: '{ "imageData" : "' + audd + '" }', contentType: 'application/json; charset=utf-8', dataType: 'json', success: function (msg) { console.log('Audio Uploaded'); } });
<system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength="50000000"/> </webServices> </scripting> </system.web.extensions>
[WebMethod()] public static void UploadAudio(string imageData) { string Pic_Path = HttpContext.Current.Server.MapPath(Guid.NewGuid().ToString() + ".wav"); using (FileStream fs = new FileStream(Pic_Path, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData); bw.Write(data); bw.Close(); } } }
Hope this help others developers to upload the audio file to the server
Jun 03, 2018 09:01 PM|DA924|LINK
Probably, no one is going to pay any attention to the answer, since it was not marked as 'answered'.
Contributor
6396 Points
2061 Posts
How to save Blob (generated in the client side) to SQL varbinary MAX
Apr 11, 2018 05:29 AM|Primillo|LINK
Hi Folks
How to save a blob generated in the client side with javascript to SQL (varbinary MAX)
I got a long string in the client side in a HiddenField value:
data:audio/wav;base64, ...
I am getting this error "Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this query."
Any better way to save audio from mobile device web page using recorder.js
Best Regards
Primillo
https://www.facebook.com/programandopuntonet
Contributor
4873 Points
4123 Posts
Re: How to save Blob (generated in the client side) to SQL varbinary MAX
Apr 11, 2018 05:43 AM|DA924|LINK
Implicit conversion from data type nvarchar to varbinary(max) is not allowed. Use the CONVERT function to run this
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
I would say that you will have to convert the nvarchar data to binary data before trying to save it without doing a conversion at the database level.
Contributor
6396 Points
2061 Posts
Re: How to save Blob (generated in the client side) to SQL varbinary MAX
Jun 03, 2018 06:54 PM|Primillo|LINK
I found a solution!
Hope this help others developers to upload the audio file to the server
Primillo
https://www.facebook.com/programandopuntonet
Contributor
4873 Points
4123 Posts
Re: How to save Blob (generated in the client side) to SQL varbinary MAX
Jun 03, 2018 09:01 PM|DA924|LINK
Probably, no one is going to pay any attention to the answer, since it was not marked as 'answered'.