function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
afs_devforceafs_devforce 

URGENT: Where to upload image file to force.com space at runtime

Hello,

 

I'm new to force.com development and running out of ideas (and time!), so help is really appreciated.

 

I have a mobile application from which the end user should be able to upload an image file to somewhere on my force.com platform, ideally a fileserver area (rather than in a databse) and then store the URL to the image within a filed of my custom object.

 

Can someone advise where I can upload the images (they will be specific to records within my custom object) I don't even know if this is possible and if so, then what objects or API I should be calling. At the moment, I was trying to use REST API via RestRequest.

 

Thanks

Navatar_DbSupNavatar_DbSup

Hi,

 

You can insert the attachment for the particular record in your custom object. In attachment object there is a parented field in which pass the id of the record in which you want to save to image or anything.

 

Use the below code snippet as reference:

StaticResource ss=[Select Name, ContentType, Body From StaticResource limit 1];

       

        Attachment Attachment1= new Attachment (Name=ss.name,contenttype=ss.contenttype,body=ss.body,IsPrivate=false,ParentId=contact.id);

         insert Attachment1;

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

afs_devforceafs_devforce

Thanks for the quick response Ankit, althought my exposure to the API is a little limited to Java (android dev) using REST, I know how to perform a regular read or update operation as below for example:

 

String objectType = "Work_Request__c";
            String objectId = mRecordID;
            Map<String, Object> fields = new HashMap<String, Object>();
            fields.put("Status__c","Complete");
            
            RestRequest request = RestRequest.getRequestForUpdate(apiVersion, objectType, objectId, fields);
            
            client.sendAsync(request, new AsyncRequestCallback() ...

 

Could I convert your snippet into a form as above or should I be looking to do something completely differed to above?