I'm building a widget in a WAB template that sends a geotagged photo to a Python toolbox GP service to create a point with the coordinates and attach the photo.
I send the request to upload:
var requestID = request({
url: "sampleurl",
content: { f: "pjson" },
form: dojo.byId("uploadForm"),
handleAs: "json"
});
Receive a successful response:
Upload Success:
{success: true, item: {…}, _ssl: undefined}
item:
committed: true
date: 1553539769324
description: null
itemID: "i697e97a0-7caa-4bac-9a5f-6e3da8ae8249"
itemName: "P_20190312_104511_gps_lig.jpg"
serviceName: "DEMO/UploadPhotoGeo.GPServer"
__proto__: Object
success: true
_ssl: undefined
__proto__: Object
Then I get the itemID and set the parameters and submit job:
requestID.then(
function (response) {
console.log("Upload Success: ", response);
itemID = response.item.itemID;
nomeItem = response.item.itemName;
params = {
"in_x": String(x_decimal),
"in_y": String(y_decimal),
"in_z": String(z.valueOf()),
"in_NIS": null,
"in_idProcDet": null,
"in_obs": null,
"in_upDate": null,
"in_photoDate": fulldate,
"in_or": null,
"in_owner": null,
"in_att": itemID,
"in_fn": nomeItem
};
var gpJob = gpTask.submitJob(params, completeCallback, statusCallback);
gpJob.then(
function (response) {
console.log("GP Success: ", response);
}, function (error) {
console.log("GP Error: ", error.message);
});
In my Python toolbox, this specific parameter is defined as:
# Eleventh parameter - Attachment
param10 = arcpy.Parameter(
displayName="Input Attachment",
name="in_att",
datatype="GPDataFile",
parameterType="Optional",
direction="Input")
And retrieved here:
foto = parameters[10].valueAsText
fotoNome = parameters[11].valueAsText
arcpy.AddMessage(str(foto))
if (foto <> None):
arcpy.AddMessage('Foto: ' + str(foto))
But I am receiving a message of a null parameter:
8:
description: "Foto: None"
type: "esriJobMessageTypeInformative"
__proto__: Object
And the script does not create the point or save the photo:
14:
description: "Gravando foto no drive f: must be string or buffer, not None"
type: "esriJobMessageTypeInformative"
Am I missing something?
Well, I feel the duty of warn those trying to use a widget in a WAB template to add a feature and attach a file to it: DO NOT try it with a python toolbox/geoprocessing service. Based on my ill fated experience, it is a HUGE headache compared to JS API. The time spent on trying it was 83 hours against 25 hours in JS API (done).
Just use
// post que envia feicao
$.post(urlAF, {
features: JSON.stringify([feature]),
f: "json"
})
.done(lang.hitch(this, function (results) {//post bem-sucedido
console.log(results);
dom.byId('upload-status').innerHTML = '<p style="color:green">Ponto criado. Adicionando anexo.</p>';
// timeout para aguardar results preenchidos e entao anexar arquivo
setTimeout(function () {
// converte json de resposta em objeto js
var resultAF = JSON.parse(results);
// converte em integer o objectId
oid = parseInt(resultAF.addResults[0].objectId);
// Trecho que adiciona anexo se insercao do ponto foi bem-sucedida
var featureLayer = new esri.layers.FeatureLayer(url, { outFields: ["*"], visible: false });
featureLayer.addAttachment(oid, document.getElementById("uploadForm"), callback, function (err) {
console.log(err);//addAttachment falhou
dom.byId('upload-status').innerHTML = '<p style="color:red">Erro ao anexar foto. Informe a equipe do SigamGeo.</p>';
});
function callback(result) {//addAttachment bem-sucedido
console.log(result);
dom.byId('upload-status').innerHTML = '<p style="color:green">Ponto criado e foto anexada.</p>';
};
}, 100);
}))
.fail(function (error) {//post falhou
console.log(error);
dom.byId('upload-status').innerHTML = '<p style="color:red">Erro na criacao do ponto. Tente novamente ou informe equipe do SigamGeo.</p>';
});