featurelayer.addAttachment is not working

557
3
05-22-2019 08:30 AM
MuralidharMoka
New Contributor II

We are tying to upload attachments using featureLayer.addAttachment operation.

We are using ArcGIS javascript API 3.8 and Emberjs.

Note: We do not have a proxy for our ArcGIS server.

// The proxy url you see does not work.

          is it necessary to use a proxy? Can we do without it.

Here is the code

file.hbs

=======

<div class="form-group">
    <div class="col-sm-12 col-md-7 col-lg-7">
        <form id="myForm">
             <div class="col-sm-8">  <input type="file"  name="attachment" /></div>
             <div class="col-sm-4">  <button class="btn btn-success" type="submit" id="upload"
                 {{action "addAttachments" }}>Submit</button></div>
        </form>
    </div>
</div>

file_controller.js

============

addAttachments:function(){
    var controller = this;
        require([
                'esri/layers/FeatureLayer'
            ],
            function (
                FeatureLayer
               ) {
                esri.config.defaults.io.proxyUrl = "https://mapviewtest.memphistn.gov/proxy/proxy.ashx";
                esri.config.defaults.io.alwaysUseProxy = false;
                var objId = controller.get('projObjectId');
                var attchUrl = App.Config.services.pmsPhotoService + objId;
                var featureLayer = new FeatureLayer(attchUrl);

                var form = document.getElementById("myForm");
                featureLayer.addAttachment(objId, form ,callback , function(err){
                   console.log(err);
                });
                function callback(result){

                    console.log(result);
                }
            });
},

Here is the log of console with all variables and err message and snap of the same log.

our attachment url has no problem.

Here is the console log

objId
      18015
attchUrl
    "https://mapviewtest.memphistn.gov/arcgis/rest/services/AGO_GeneralServices/PMS_WOMS/FeatureServer/1/..."

<form id="myForm"><div class="col-sm-8"><input type="file" name="attachment"></div><div class="col-sm-4">…</div></form>
dev.html#/projectDashBoard:1 Access to XMLHttpRequest at 'https://mapviewtest.memphistn.gov/proxy/proxy.ashx?https://mapviewtest.memphistn.gov/arcgis/rest/ser...' from origin 'http://localhost:9876' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
init.js:187 r {message: "Unable to load https://mapviewtest.memphistn.gov/p…atureServer/1/18015/18015/addAttachment status: 0", response: {…}, status: 0, responseText: "", xhr: XMLHttpRequest, …}
w @ init.js:187
(anonymous) @ init.js:186
c @ init.js:74
d @ init.js:74
resolve.callback @ init.js:75
c @ init.js:74
d @ init.js:74
reject.errback @ init.js:76
c @ init.js:74
d @ init.js:74
reject.errback @ init.js:76
c @ init.js:74
d @ init.js:74
reject.errback @ init.js:76
(anonymous) @ init.js:190
f @ init.js:194
q @ init.js:194
w.reject @ init.js:197
a @ init.js:195
f @ init.js:195
q @ init.js:194
w.reject @ init.js:197
a @ init.js:195
f @ init.js:195
q @ init.js:194
w.reject @ init.js:197
a @ init.js:195
f @ init.js:195
q @ init.js:194
w.reject @ init.js:197
a @ init.js:195
f @ init.js:195
q @ init.js:194
w.reject @ init.js:197
r @ init.js:156
h @ init.js:160
error (async)
d @ init.js:160
f @ init.js:157
b.xhr @ init.js:190
b.rawXhrPost.b.xhrPost @ init.js:191
v @ init.js:466
d @ init.js:468
B @ init.js:473
_sendAttachment @ FeatureLayer.js:86
addAttachment @ FeatureLayer.js:55
(anonymous) @ app/controllers/projectDashBoard_controller.js:779
ga @ init.js:32
(anonymous) @ init.js:24
ha @ init.js:32
Ma @ init.js:24
p @ init.js:15
addAttachments @ app/controllers/projectDashBoard_controller.js:766
send @ lib-dev.js:34902
(anonymous) @ lib-dev.js:53661
run @ lib-dev.js:24306
Ember.run @ lib-dev.js:24685
handler @ lib-dev.js:53659
(anonymous) @ lib-dev.js:38415
Ember.handleErrors @ lib-dev.js:19257
(anonymous) @ lib-dev.js:38407
dispatch @ lib-dev.js:9009
elemData.handle @ lib-dev.js:8685
Show 6 more frames
err
r {message: "Unable to load https://mapviewtest.memphistn.gov/p…atureServer/1/18015/18015/addAttachment status: 0", response: {…}, status: 0, responseText: "", xhr: XMLHttpRequest, …}log: undefinedmessage: "Unable to load https://mapviewtest.memphistn.gov/proxy/proxy.ashx?https://mapviewtest.memphistn.gov/arcgis/rest/ser... status: 0"response: {url: "https://mapviewtest.memphistn.gov/proxy/proxy.ashx…MS_WOMS/FeatureServer/1/18015/18015/addAttachment", options: a, getHeader: ƒ, xhr: XMLHttpRequest, status: 0, …}responseText: ""status: 0xhr: XMLHttpRequest {onreadystatechange: null, readyState: 0, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, …}_ssl: undefinedstack: "Error: Unable to load https://mapviewtest.memphistn.gov/proxy/proxy.ashx?https://mapviewtest.memphistn.gov/arcgis/rest/ser... status: 0↵ at new r (http://js.arcgis.com/3.8compact/init.js:221:367)↵ at XMLHttpRequest.h (http://js.arcgis.com/3.8compact/init.js:160:167)"__proto__: Error

0 Kudos
3 Replies
VictorTey
Esri Contributor

Hi,

I am confused, are you or are you not using a proxy?

You are attempting to route to https://mapviewtest.memphistn.gov/proxy/proxy.ashx? which is a esri proxy

https://github.com/Esri/resource-proxy

can you test https://mapviewtest.memphistn.gov/proxy/proxy.ashx?ping

0 Kudos
MuralidharMoka
New Contributor II

Hi,

Thanks for the response.

We are not using the proxy. We want to do without the proxy.

Thanks

Muralidhar Moka

0 Kudos
VictorTey
Esri Contributor

As long as there are no cors issue and you can manage the authentication, I don't see why not. 

0 Kudos