Trouble with AddItem operation

3856
1
06-04-2014 11:02 AM
ChristopherHooe
New Contributor
Hello, I'm having an issue attempting to interact with a REST endpoint via the AddFile operation.

Following along with the documentation here, I've created a POST operation specifying my token, item title, item file type, and response format. In different requests I've attempted to specify the file as the data of the file itself via the "file" parameter, and separately as plaintext via the "text" parameter (the file in question is a small comma-separated value file, about 160 bytes).

Regardless of manner used to specify the file in that last point, I run the constructed operation, I receive a success response back from the REST endpoint with the success field as true and the new file's ID on the endpoint. However, when I attempt to download the file via the ArcGIS online portal as a sanity check (i.e. logging in to ArcGIS.com and viewing my content), I receive "Error 500 - Item does not have a file".

What if anything am I overlooking here? I'm fairly new to ArcGIS specifically, so I'm learning on the fly here and have managed up to this point but with this particular bit I'm a bit stumped.

Any assistance or advice is appreciated. Thanks!
0 Kudos
1 Reply
DavidWilton
Occasional Contributor

Here is a JavaScript $ dojo sample I created which uploads a json file. It is small json file created dynamically on the client side. You would send your token in the content object if you had one.

              var myJson = JSON.stringify(this._serializeGraphics({myProp: myVal}));

              var blob = new Blob([myJson], { type: "application/json" });

              var formNode = put("form", {

                  "method": "post",

                  "enctype": "multipart/form-data"

              });

              var formData = new FormData(formNode);

              formData.append("itemType", "file");

              formData.append("type", "GeoJson");

              formData.append("title", this.title);

              formData.append("file", blob, this.filename);

               var path = "content/users/" + this.portalUser.username + '/' + folder + "/addItem";

               return esriRequest({

                      url: this.portal.portalUrl + path,

                      form: formData,

                      content: {

                          f: "json"

                      }

                }, { usePost: true }).then(this._saveSuccessful, this._error);

0 Kudos