7

I have an apex method that takes in a Blob input argument and needs to be called from javascript. When I pass in a Javascript Blob, I get what seems to a be type mismatch error from VFRemote.js:

"Visualforce Remoting Exception: Unexpected type for TestClass.testRemoteAction(Blob)" {statusCode: 400, type: "exception", tid: 2, ref: false, action: "TestClass", method: "testRemoteAction", message: "Unexpected type for TestClass.testRemoteAction(Blob)", where: "", data: Array[1], vfTx: true, 2 more…} VFRemote.js:116 null

Here's my javascript snippet:

var binaryMsg = new Uint8Array(message);
var blobMsg = new Blob(binaryMsg, {type: "octet-stream"});
Visualforce.remoting.Manager.invokeAction(
   '{!$RemoteAction.TestClass.testRemoteAction}',
   blobMsg,
   function(result, event) {console.log(result);}
);
1
  • 2
    It's a bit of a cop-out, but you could change your apex method to accept a base64 encoded string and then convert it back to a Blob using EncodingUtil.base64Decode(String) Commented May 15, 2014 at 22:56

1 Answer 1

8

You can't directly construct Blobs through remoting right now. You are basically limited to things that you can put in JSON, which means that you need to make the payload binary-safe. Encode the contents in either Base64 encoding or URL-encoding, then decode it on the server side using one of the functions available for that purpose.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.