Hey,
This isn't ebase related directly....just something I am hoping to achieve with Ebase.
Essentially I am using release 5.1 and the REST resources to successfully create/lookup records in Salesforce. A new piece of functionality I want to create is the ability to insert an Attachment.
I am currently using the Ebase functionality to allow users to upload attachments, these end up on the ebase server just now...what I am struggling with is how to convert these to "something" that I could then POST back to Salesforce as an Attachment record (Blob, base64 etc).
Can anyone explain how I could achieve this in Ebase? Apologies...the first time in doing something is always the hardest.
Lacking experience...REST Attachment
Moderators: Jon, Steve, Ian, Dave
-
- Ebase User
- Posts: 95
- Joined: Wed Feb 27, 2013 5:16 pm
-
- Moderator
- Posts: 419
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi Alex,
I am not really familiar with Salesforce. but reading on the forum you could attach these as a Content-Type: multipart/form-data;
https://developer.salesforce.com/docs/a ... e_blob.htm
The REST API does not support multipart form data, so you will probably have to build this yourself:
https://hc.apache.org/httpcomponents-cl ... mPost.java
Either that, or you could maybe base64encode the file and add as a parameter to the request? I am not sure what would happen to it on SalesForce though.
I am not sure if this information helps...
Steve
I am not really familiar with Salesforce. but reading on the forum you could attach these as a Content-Type: multipart/form-data;
https://developer.salesforce.com/docs/a ... e_blob.htm
The REST API does not support multipart form data, so you will probably have to build this yourself:
https://hc.apache.org/httpcomponents-cl ... mPost.java
Either that, or you could maybe base64encode the file and add as a parameter to the request? I am not sure what would happen to it on SalesForce though.
I am not sure if this information helps...
Steve
0 x
-
- Ebase User
- Posts: 95
- Joined: Wed Feb 27, 2013 5:16 pm
Thanks Steve,
I've been reading a lot of that today. I was hoping you had a sample/example of converting the file from the server to blob or encoded etc?
I have tried a few things, mostly client side without success, still googling though! Worth noting my REST API can create the "Attachment" record as I would expect...I am just missing how to convert the file to the right format to post.
I've been reading a lot of that today. I was hoping you had a sample/example of converting the file from the server to blob or encoded etc?
I have tried a few things, mostly client side without success, still googling though! Worth noting my REST API can create the "Attachment" record as I would expect...I am just missing how to convert the file to the right format to post.
0 x
-
- Moderator
- Posts: 419
- Joined: Fri Sep 07, 2007 3:44 pm
- Location: Sandy, UK
- Contact:
Hi Alex...
I wrote a function to Base64Encode a file:
Note that you will need the Apache commons IO jar file in your WEB-INF/lib folder of the Ebase server. If you are using version 5.1 of Ebase, then you should have this already.
Also note that javaScript does not cope with byte[] very well, so I have used Java reflection to create a byte array. See the line that creates buffer.
I hope this helps
Steve
I wrote a function to Base64Encode a file:
Code: Select all
importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);
importPackage(java.io);
importClass(org.apache.commons.codec.binary.Base64);
var filename = "C:/Temp/testPic.png";
controls.TXT.text.text = encodeFileToBase64Binary(filename);
function encodeFileToBase64Binary(filename){
var encodedfile = null;
try {
var file = new File(filename);
var fileInputStreamReader = new FileInputStream(file);
var buffer = new Packages.java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, file.length());
fileInputStreamReader.read(buffer);
encodedfile = Base64.encodeBase64String(buffer);
}
catch (e)
{
log(e);
}
return encodedfile;
}
Also note that javaScript does not cope with byte[] very well, so I have used Java reflection to create a byte array. See the line that creates buffer.
I hope this helps
Steve
0 x
-
- Ebase User
- Posts: 95
- Joined: Wed Feb 27, 2013 5:16 pm
Who is online
Users browsing this forum: No registered users and 14 guests