Uploading an image for Azure Sphere public API

Adam Dolman 6 Reputation points
2020-12-08T09:03:17.173+00:00

We are trying to automate to make use of the API to upload an image to Sphere. The API documents the image should be sent as a byte array, but it doesn't look like our script is successful in uploading, as the get async operation doesn't seem to return success.

Our code is:

$bitstream = @()
$bitstream = get-content $image -encoding byte
$body = ""$bitstream""
$tempresult = invoke-restmethod -Method Post -uri "https://prod.core.sphere.azure.net/v2/tenants/$primarytenant/images" -Headers @{ 'Authorization' = "Bearer $bearertoken"; 'Content-Type' = 'application/json' } -Body $body
$tempresult
$opid = $tempresult.OperationId
sleep 5
invoke-restmethod -Method Get -uri "https://prod.core.sphere.azure.net/v2/tenants/$primarytenant/operations/$opid/" -Headers @{ 'Authorization' = "Bearer $bearertoken"; 'Content-Type' = 'application/json' }

The operation shows the following:

TenantId : x
OperationId : c2b6dedd-0313-4feb-81dc-96762231dd9c
CreatedDateUTC : 2020-12-08T08:52:44.59309Z
StartedDateUTC : 2020-12-08T08:52:44.8275573Z
CompletedDateUTC : 2020-12-08T08:52:45.0375127Z
OperationType : 7
State : 3
ResourceLocation :
DetailsLocation : v2/tenants/x/operationTypes/imageUpload/operations/c2b6dedd-0313-4feb-81dc-96762231dd9c
Error : @{Code=5; Message=}

But I can't understand why it doesn't work. I've tried passing the bitstream directly, instead of as a string, but to no impact.

Thanks for any ideas!

Azure Sphere
Azure Sphere
An Azure internet of things security solution including hardware, operating system, and cloud components.
166 questions
{count} votes

1 answer

Sort by: Most helpful
  1. QuantumCache 20,261 Reputation points
    2020-12-16T07:16:20.217+00:00

    Hello @Adam Dolman , Have you tried via postman regarding the Image Upload operation?

    I have tried with Postman and was able to upload the image file. Can you please try with the postman and do let us know.

    48597-image.png

    Basically, Error code 5 means it has to be one from this list. I don't have the exact enum sequence as of this time.

    • BadRequest
    • ClientUpdateRequired
    • Conflict
    • Forbidden
    • InternalServerError
    • NotFound
    • OperationFailed
    • TenantInMigration
    • TenantMigrationRequired

    Please comment in the below section if you need further help in this matter.