How I can save a file into BLOB field?

2436
4
05-03-2017 11:50 PM
DairisTapanes_Rios
New Contributor

Hi,

I'm trying to do something like when you enable attachments, but I need to have more control over the attachment table , so I created the attachment table that contain the attachment files and more attributes and I want use  applyEdits to add and edit features. I'm wondering how I can insert a file chosen by the client into the BLOB field, please any idea would be great!!s

thanks 

Dairis

0 Kudos
4 Replies
AndyGup
Esri Regular Contributor

Just making sure, is this is a JavaScript app? And, are you programmatically making your own ArcGIS REST API calls for editing attachments in a feature service? 

If so, then attachments are handled using addAttachment, updateAttachment and deleteAttachments

With respect to your attachments, when you do add an attachment I recommend using FormData to create your XMLHttpRequest:

    // Example when adding an attachment
    var formData = new FormData();
    formData.append("attachment",file);‍‍‍‍

    // Example when updating an attachment
    formData.append("attachmentId", attachment.id);‍‍‍‍‍‍

You can see an example of working with attachments using the ArcGIS JavaScript API and the attachment widget here: SanFrancisco311 - Incidents 

Here's an example of the HTTP request when making an addAttachment. You can see this for yourself in the browser's developer tools under the network tab. 

------WebKitFormBoundary1aQsyoAkAGZU7oKM Content-Disposition: form-data; name="attachment"; filename="Blue Lake.jpg" Content-Type: image/jpeg 

------WebKitFormBoundary1aQsyoAkAGZU7oKM Content-Disposition: form-data; name="f" json 
------WebKitFormBoundary1aQsyoAkAGZU7oKM--‍‍‍‍

If a request is successful you'll see a response in the network tab similar to this:

{
  "addAttachmentResult" : {
     "objectId" : 7369, 
     "globalId" : null, 
     "success" : true
  }
}

-Andy

0 Kudos
DairisTapanes_Rios
New Contributor

Hi Andy,

Thank you for you quickly answer.

Sorry if I don't explain me very well . 

Yes, it is a JavaScript app but I don't want to enable attachments on the features classes because same document could be attachment to different features classes.

Then I come with the  idea to create a table that contain all the documents and create a relationship N:M to the different features classes that will have associated those attachments.

In that case I can't use addAttachment, updateAttachment and deleteAttachments.

That is why I'm wondering how to insert a BLOB field on ArcGIS Server Rest API, I read that  "the ArcGIS Server REST API does not support BLOBs", is it true ? if so,  what I can do ? Could you give better idea to handle that ?

Thanks,

Dairis 

0 Kudos
AndyGup
Esri Regular Contributor

Correct, there is no support for BLOBs, reference: ArcGIS REST API.

Feature object attributes are stored in JSON. Field values can be string, number or boolean.

-Andy 

0 Kudos
DairisTapanes_Rios
New Contributor

Thank you so much !

0 Kudos