c# - How to submit a file to an ASP.NET Core application -


i have asp.net application presents simple form upload files (images). looks this:

public iactionresult process() {     return view(); }  [httppost] public iactionresult process(list<iformfile> files) {     var telemetry = new telemetryclient();     try     {         var result = files.count + " file(s) processed " + environment.newline;         foreach (var file in files)         {             result += file.filename + environment.newline;             var memorystream = new memorystream();             file.copyto(memorystream);             memorystream.seek(0, seekorigin.begin);             var binaryreader = new binaryreader(memorystream);             var bytes = binaryreader.readbytes((int)memorystream.length);              var imageinformation = imageservice.processimage(bytes);              imageservice.saveimage(imageinformation.result, bytes, file.filename.substring(file.filename.lastindexof(".", stringcomparison.ordinal) + 1));         }          return view((object)result);     }     catch (exception ex)     {         telemetry.trackexception(ex);         throw;     } } 

this form in application works fine. problem want use microsoft flow submit files come sharepoint library on web application defined above.

i have file flow setup , runs , doesn't error out, when @ body of http action's result says 0 files processed , nothing gets done.

the flow have setup

  1. when file created (sharepoint) (this pointing specific document library
  2. http (http), method: post, uri (pointing app), body: file content sharepoint step above.

as mentioned posting site, must not passing in file in way asp.net method can handle, not processing anything. how can change either flow or post method, work.

updated new information have tried small image, can additional request information. using form in browser tried , going following request raw result using fiddler:

post https://os-gbsphotoretain.azurewebsites.net/image/process http/1.1 host: os-gbsphotoretain.azurewebsites.net connection: keep-alive content-length: 924 pragma: no-cache cache-control: no-cache origin: https://os-gbsphotoretain.azurewebsites.net upgrade-insecure-requests: 1 user-agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, gecko) chrome/60.0.3112.90 safari/537.36 content-type: multipart/form-data; boundary=----webkitformboundarysjqvgrsvaqjyxmst accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 referer: https://os-gbsphotoretain.azurewebsites.net/image/process accept-encoding: gzip, deflate, br accept-language: en-us,en;q=0.8 cookie: _ga=ga1.3.955734319.1501514097; ai_user=ukqsf|2017-07-31t15:17:38.409z; arraffinity=1628d46398b292eb2e3ba76b4b0f1eb1e30abd9bd1036d7a90b9c51f7baa2306; ai_session=/fpfh|1502738361594.15|1502738361594.15  ------webkitformboundarysjqvgrsvaqjyxmst content-disposition: form-data; name="files"; filename="printer.jpg" content-type: image/jpeg       jfif  ` `     c                 $.' ",#(7),01444'9=82<.342   c            2!!22222222222222222222222222222222222222222222222222     "                          } !1aqa "q2   #b  r  $3br     %&'()*456789:cdefghijstuvwxyzcdefghijstuvwxyz                                                                                                w !1aq aq"2 b        #3r br  $4 % &'()*56789:cdefghijstuvwxyzcdefghijstuvwxyz                                                                             ?       +x k     21 c z  ] Ó¥g v  ; :          p     f >   m;] ֬u nm   ` q 1 p6 s 9 |b r|   g   ------webkitformboundarysjqvgrsvaqjyxmst-- 

doing same image through flow following body in flow:

{   "$content-type": "image/jpeg",   "$content": "/9j/4aaqskzjrgabaqeayabgaad/2wbdaaggbgcgbqghbwcjcqgkdbqndasldbksew8uhrofhh0ahbwgjc4nicisixwckdcpldaxndq0hyc5ptgypc4zndl/2wbdaqkjcqwldbgndrgyirwhmjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjl/waarcaaqabadasiaahebaxeb/8qahwaaaqubaqebaqeaaaaaaaaaaaecawqfbgcicqol/8qatraaagedawieawufbaqaaaf9aqidaaqrbrihmuege1fhbyjxfdkbkaeii0kxwrvs0fakm2jyggkkfhcygroljicokso0nty3odk6q0rfrkdisuptvfvwv1hzwmnkzwznaglqc3r1dnd4exqdhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2uhi4+tl5ufo6erx8vp09fb3+pn6/8qahweaawebaqebaqebaqaaaaaaaaecawqfbgcicqol/8qatreaagecbaqdbacfbaqaaqj3aaecaxeebsexbhjbuqdhcrmimoeifekrobhbcsmzuvavynlrchyknoel8rcygromjygpkju2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6gooehyahiimkkpoulzaxmjmaoqokpaanqkmqsro0tba3ulm6wspexcbhymnk0tpu1dbx2nna4upk5ebn6onq8vp09fb3+pn6/9oadambaairaxeapwd1c9emuqzgk1jus+3p7rccgc4ymyxjv1q/ol0i4bftpqvnixaoyduqhjotg7ccgsdu7o+0+xedojfmukike84mb/dj5b9mzj6vnefto1271qx1g+hubagbjmcsufmsmzzqnoxzgdnpfgkqcnypejw1r//z" } 

so looks flow submitting json. i'm going try additional processing test, if knows can put in web app handle appreciate it.

i added new method see below works when run locally passing in string flow says body. when run flow value cannot null error in deserializeobject line. how can information flow passing in.

[httppost]     public iactionresult processjson(string json)     {         var telemetry = new telemetryclient();         try         {             var result = "json processed " + environment.newline;             var details = (dynamic)newtonsoft.json.jsonconvert.deserializeobject(json);             var content = (string) details["$content"];             var bytes = convert.frombase64string(content);              processbytes(bytes, "jpeg");             return view("process", result);         }         catch (exception ex)         {             telemetry.trackexception(ex);             throw;         }     } 

i have tried method signature, no luck there either comes in null

        [httppost]         public iactionresult processjson([frombody]flowfile file)         { ...         }     public class flowfile     {          [jsonproperty(propertyname = "$content-type")]         public string contenttype { get; set; }         [jsonproperty(propertyname = "$content")]         public string content { get; set; }     } 

i added middleware, raw request.body , end result comes this. i'm not sure equates to.

&#xd;&#xa;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#x0;&#x10;jfif&#x0;&#x1;&#x1;&#x1;&#x0;`&#x0;`&#x0;&#x0;&#xfffd;&#xfffd;&#x0;c&#x0;&#x8;&#x6;&#x6;&#x7;&#x6;&#x5;&#x8;&#x7;&#x7;&#x7;&#x9;&#x9;&#x8;&#xa;&#xc;&#x14;&#xd;&#xc;&#xb;&#xb;&#xc;&#x19;&#x12;&#x13;&#xf;&#x14;&#x1d;&#x1a;&#x1f;&#x1e;&#x1d;&#x1a;&#x1c;&#x1c; $.&#x27; &quot;,#&#x1c;&#x1c;(7),01444&#x1f;&#x27;9=82&lt;.342&#xfffd;&#xfffd;&#x0;c&#x1;&#x9;&#x9;&#x9;&#xc;&#xb;&#xc;&#x18;&#xd;&#xd;&#x18;2!&#x1c;!22222222222222222222222222222222222222222222222222&#xfffd;&#xfffd;&#x0;&#x11;&#x8;&#x0;&#x10;&#x0;&#x10;&#x3;&#x1;&quot;&#x0;&#x2;&#x11;&#x1;&#x3;&#x11;&#x1;&#xfffd;&#xfffd;&#x0;&#x1f;&#x0;&#x0;&#x1;&#x5;&#x1;&#x1;&#x1;&#x1;&#x1;&#x1;&#x0;&#x0;&#x0;&#x0;&#x0;&#x0;&#x0;&#x0;&#x1;&#x2;&#x3;&#x4;&#x5;&#x6;&#x7;&#x8;&#x9;&#xa;&#xb;&#xfffd;&#xfffd;&#x0;&#xfffd;&#x10;&#x0;&#x2;&#x1;&#x3;&#x3;&#x2;&#x4;&#x3;&#x5;&#x5;&#x4;&#x4;&#x0;&#x0;&#x1;}&#x1;&#x2;&#x3;&#x0;&#x4;&#x11;&#x5;&#x12;!1a&#x6;&#x13;qa&#x7;&quot;q&#x14;2&#xfffd;&#xfffd;&#xfffd;&#x8;#b&#xfffd;&#xfffd;&#x15;r&#xfffd;&#xfffd;$3br&#xfffd;&#x9;&#xa;&#x16;&#x17;&#x18;&#x19;&#x1a;%&amp;&#x27;()*456789:cdefghijstuvwxyzcdefghijstuvwxyz&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#x0;&#x1f;&#x1;&#x0;&#x3;&#x1;&#x1;&#x1;&#x1;&#x1;&#x1;&#x1;&#x1;&#x1;&#x0;&#x0;&#x0;&#x0;&#x0;&#x0;&#x1;&#x2;&#x3;&#x4;&#x5;&#x6;&#x7;&#x8;&#x9;&#xa;&#xb;&#xfffd;&#xfffd;&#x0;&#xfffd;&#x11;&#x0;&#x2;&#x1;&#x2;&#x4;&#x4;&#x3;&#x4;&#x7;&#x5;&#x4;&#x4;&#x0;&#x1;&#x2;w&#x0;&#x1;&#x2;&#x3;&#x11;&#x4;&#x5;!1&#x6;&#x12;aq&#x7;aq&#x13;&quot;2&#xfffd;&#x8;&#x14;b&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#x9;#3r&#xfffd;&#x15;br&#xfffd;&#xa;&#x16;$4&#xfffd;%&#xfffd;&#x17;&#x18;&#x19;&#x1a;&amp;&#x27;()*56789:cdefghijstuvwxyzcdefghijstuvwxyz&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#x0;&#xc;&#x3;&#x1;&#x0;&#x2;&#x11;&#x3;&#x11;&#x0;?&#x0;&#xfffd;&#xb;&#xfffd;&#xc;&#xfffd;&#xfffd;&#xfffd;&#x2b;x&#xfffd;k&#xfffd;&#xfffd;&#xfffd;&#x1c;&#xfffd;&#xfffd;21&#xfffd;c&#xfffd;z&#xfffd;&#xfffd;]&#x8;&#xfffd;&#x4e5;&#x5;g&#xfffd;v&#xfffd;&#xfffd;;&#xfffd;&#x1e;:&#x13;&#xfffd;&#xfffd;&#x1c;&#x1a;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#xfffd;&#x11;&#x1d;&#xfffd;&#xfffd;&#xfffd;p&#xfffd;&#xfffd;&#x13;&#xfffd;&#xc;&#x7;&#xfffd;i&#xfffd;&#x1f;f&#xfffd;&gt;&#xfffd;&#xfffd;&#xfffd;m;]&#xfffd;&#x5ac;u&#x1b;&#xfffd;nm&#xfffd;&#xfffd;&#xfffd;`&#xfffd;q&#xfffd;&#x12;1&#xfffd;p6&#xfffd;s&#xfffd;9&#xfffd;|b&#xfffd;r|&#xfffd;&#x10;&#xfffd;&#xfffd;g&#xfffd; 

well little bit unclear me how file send: json object file converted base64 string or file content? (html headers indicators)

if have json theory do:

var parsedfilecontent = newtonsoft.json.jsonconvert.deserializeobject<flowfile>(json); 

instead of

var details = (dynamic)newtonsoft.json.jsonconvert.deserializeobject(json); 

and should work, if , if ;), posted correct

{   "$content-type": "image/jpeg",   "$content": "/9j/4aaqskzjrgabaqeayabgaad/2wbdaaggbgcgbqghbwcjcqgkdbqndasldbksew8uhrofhh0ahbwgjc4nicisixwckdcpldaxndq0hyc5ptgypc4zndl/2wbdaqkjcqwldbgndrgyirwhmjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjiymjl/waarcaaqabadasiaahebaxeb/8qahwaaaqubaqebaqeaaaaaaaaaaaecawqfbgcicqol/8qatraaagedawieawufbaqaaaf9aqidaaqrbrihmuege1fhbyjxfdkbkaeii0kxwrvs0fakm2jyggkkfhcygroljicokso0nty3odk6q0rfrkdisuptvfvwv1hzwmnkzwznaglqc3r1dnd4exqdhiwgh4ijipktljwwl5izmqkjpkwmp6ipqrkztlw2t7i5usldxmxgx8jjytlt1nxw19jz2uhi4+tl5ufo6erx8vp09fb3+pn6/8qahweaawebaqebaqebaqaaaaaaaaecawqfbgcicqol/8qatreaagecbaqdbacfbaqaaqj3aaecaxeebsexbhjbuqdhcrmimoeifekrobhbcsmzuvavynlrchyknoel8rcygromjygpkju2nzg5okneruzhselku1rvvldywvpjzgvmz2hpann0dxz3ehl6gooehyahiimkkpoulzaxmjmaoqokpaanqkmqsro0tba3ulm6wspexcbhymnk0tpu1dbx2nna4upk5ebn6onq8vp09fb3+pn6/9oadambaairaxeapwd1c9emuqzgk1jus+3p7rccgc4ymyxjv1q/ol0i4bftpqvnixaoyduqhjotg7ccgsdu7o+0+xedojfmukike84mb/dj5b9mzj6vnefto1271qx1g+hubagbjmcsufmsmzzqnoxzgdnpfgkqcnypejw1r//z" } 

just make sure json in single line string (make sure there no hidden chars \n or similar)

on other hand, in fidler capture have:

content-type: multipart/form-data;

so correct way go iformfile

so information provided little bit misleading. can try , pass bigger chuck of error logs? "object reference not sent instance of object error" general , kinds of errors narrowed down stack trace.


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -