Select to view content in your preferred language

Attachment URL with Token

1772
12
03-03-2023 04:18 PM
DavidPuckett
Occasional Contributor


I have used the example in the attachments sample to 'manually' construct a url for an attachment

For unsecured services\attachments, I can set an Image source to this url successfully.
E.g.

const attachmentUrl = featureLayerUrl + "/" + oid + "/attachments/" + attachment.attachmentId

However, for secured services, constructing the url in this way and then appending the Credential token does not work.
E.g.

const attachmentUrl = featureLayerUrl + "/" + oid + "/attachments/" + attachment.attachmentId + "?token=" + app.portal.credential.token

The image status reports an Image.Error

onStatusChanged: if (thumbnail.status === Image.Error) workRecordThumbnail.source = "../assets/image-error.png"

The portal credential works to access the services (feature layers) but it seems I cannot simply append the credential token to the attachment url to view the attachment.

I am creating the Credential like this:

Credential {
  id: portalCredential
  oAuthClientInfo: OAuthClientInfo {
    oAuthMode: Enums.OAuthModeUser
    clientId: app.clientId
  }
}


Any help?

0 Kudos
12 Replies
ZachBray
New Contributor II

I was able to copy and paste the url string from Postman with a recent token value into a Chrome browser window and get the attachment.  We have a federated Portal, Server setup as well.  I got my token through https://my_webadapter_server/portal/sharing/rest/generateToken.  I supplied a username, password, client = referer, f=json, referer=https://my_webadapter_server/server as the form body.

Hope this helps.

0 Kudos
DavidPuckett
Occasional Contributor

So I created a QML NetworkRequest that I used to POST a request using the url to the attachment image and passing the token, f:json and referer into the request. I got back the same web adaptor error, as html 😔 Thanks for the suggestions again @ZachBray but I'm afraid there is something happening with the token that is being generated. I remain open to ideas however...

0 Kudos
ZachBray
New Contributor II

I was using the generateToken endpoint and it looks like you are using the oauth2 endpoint.  I was able to get an access_token using .../rest/oauth2/authorize?client_id=????&response_type=token&redirect_uri=????.  I could then copy paste the access_token into my same attachments request in a Chrome browser Window and get the image back.  So I would think that this should work.  

Your error message indicated that it could not find any server machines.  Is there any potential networking issues, your machine not able to get to the server?  Was the Feature Service you are working with published with attachments enabled?  Are you able to access the attachment through another method, I confirmed mine through ArcGIS Pro and by making an attachments info call which is just .../FeatureServer/layer_id/objectId/attachments.  The attachments info call is where I got the attachment object id I need to get the actual image back.  Can you return just your expected access_token so that you could copy it into a browser window to confirm it is valid?

Just throwing out somethings that might jog your memory.  I was able to make this work in my environment, so you should be able to as well.

Good luck. 

0 Kudos