Upload Binary Content

You can upload binary content to any force.com endpoint that supports the binary upload feature.

The sendRequest() method in react.force.net.js has a new optional parameter named fileParams.

1function sendRequest(endPoint, path, successCB, errorCB, method, payload, headerParams, fileParams)

This parameter expects the following form:

1{
2    <fileParamNameInPost>: // value depends on the endpoint
3    {
4        fileMimeType:<SOMEMIMETYPE>,  
5        fileUrl:<FILEURL>, // url to file to upload
6        fileName:<FILENAMEFORPOST>
7    }
8}

For example:

1{
2    fileUpload:
3    {
4        fileMimeType:'image/jpeg',
5        fileUrl:localPhotoUrl,
6        fileName:'pic.jpg'
7    }
8}

Example 

The github.com/wmathurin/MyUserPicReactNative sample app demonstrates binary upload. This sample allows you to change your profile picture. Binary upload of the new pic happens in the uploadPhoto() function of the UserPic.js file.

Here’s the sample’s sendRequest() call in the getUserInfo() function:

1getUserInfo(callback) {
2    forceClient.sendRequest('/services/data',
3        '/v36.0/connect/user-profiles/' + this.state.userId + '/photo',            
4        (response) => {                
5            callback(response);            
6        },            
7        (error) => {                
8            console.log('Failed to upload user photo:' + error);            
9        },            
10        'POST',            
11        {},            
12        {'X-Connect-Bearer-Urls': 'true'},            
13        {fileUpload:
14            {
15                fileUrl:localPhotoUrl,
16                fileMimeType:'image/jpeg',
17                fileName:'pic.jpg'
18            }
19        }       
20    );
21},

We've Moved

Welcome to the new home of the Mobile SDK Developer Guide! For now, the Japanese guide can be found in PDF form.