Getting Image from API, then storing it as Azure Storage Blob (image error) -


so i'm trying this:

  1. get users ad using graph api in azure function (c# or node)
  2. for each user, photo, using graph api (in same azure function)
  3. with photo data, upload blob azure storage

now, have 1 , 2 working correctly. now, have no idea how convert image/jpeg string blob in azure storage. i've tried lot, researched lot it's been difficult.

i've tried use

blob.properties.contenttype = "image/jpeg" blob.uploadtext(imgstring); 

but doesn't work.

so code looks this:

  1. i fresh oauth token azure (good 3600 sec)
  2. get /users ad graph api
  3. for each user, use /user//photo/$value resource, returns image/jpeg data.
  4. from data (a string?) try blob.uploadtext fails.

the way i'm getting image data graphapi using restsharp, this:

var client = new restclient("https://graph.microsoft.com/v1.0/users/" + email + "/photo/$value"); var request = new restrequest(method.get); request.addheader("cache-control", "no-cache"); request.addheader("authorization", "bearer " + token); request.addheader("content-type", "image/jpeg"); return client.execute(request); 

so return irestresponse, contains this:

response.contenttype //to content type response.content // body (the image) blob.uploadtext(response.content); 

and that's i'm trying do, doesn't work, file gets saved ok when open it, can't see image. think issue might encoding, i've tried setting different encoding types no luck.

take @ next picture. right, got image graph api using php, , set header image/jpeg, echo image data , that's it. works. on left, it's azure function javascript or c#, image , when try same (show in browser) different binary string , no picture on page (like if wasn't image data), looks if problem encoding. i'm saving binary data on blob file uploadtext it's not working.

encoding

any ideas?

any ideas?

please have use rawbytes blob content. works correctly on side.

blob.uploadfrombytearray(response.rawbytes,0,response.rawbytes.length-1);  

the following test demo code

var connectionstring = "storage connection string"; cloudstorageaccount storageaccount =  cloudstorageaccount.parse(connectionstring); cloudblobclient blobclient = storageaccount.createcloudblobclient(); cloudblobcontainer container =  blobclient.getcontainerreference("container"); container.createifnotexists(); cloudblockblob blob = container.getblockblobreference("test.jpeg");         blob.uploadfrombytearray(response.rawbytes,0,response.rawbytes.length-1);  

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -