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?
Have you tried including the f query parameter to your attachmentURL?
const attachmentUrl = featureLayerUrl + "/" + oid + "/attachments/" + attachment.attachmentId + "?f=json&token=" + app.portal.credential.token
Thanks for the idea but it didn't resolve the issue. Still can't get to the attachment.
I ran the following through Postman and got the image back. Where 209 is the Feature ObjectId and 144 is the attachment objectid from the attachments info endpoint, attachments. I had content type set to application/json
Forgot to mention, I added the w query parameter as referenced in the REST API docs.
https://developers.arcgis.com/rest/services-reference/enterprise/attachment-feature-service-.htm
@ZachBraythank you for this. So did you have an issue with using the url with a token as the source for an image? But using a Post worked for you? If so, I would be curious how you set the image source to the response from the Post request.
Hi @DavidPuckett,
Using the online map viewer and checking the network traffic, it looks like your url format is correct.
This is for OID=1, which only has one attachment (text file seen below).
Once you're logged in and have the token, if it's not working in the app I'd copy/paste that into the browser and see if that works.
Pasting the url with the token from my app doesn't work either. I get an error from Web Adaptor saying 'Could not access any server machines. Please contact you system administrator'. So I guess the question is, why doesn't the token generated from the credential when a named user signs in work to get access to the attachments?
@DavidPuckett I am not sure, unfortunately. There may be some additional level of complexity in your situation compared to what I've tested. If @ZachBray 's suggestions don't help, I recommend reaching out to support so we can further help you.
I suspect you are right @JamesBallard1 We have a complex federated enterprise portal in place... thank you for the input.
I am curious if others have successfully used the attachment url with a token to display image attachments that are in secure portal environments however. Like, is this *supposed* to work ?! :collision:😎