c# - WCF RESTful service - upload two files -
i need upload 2 files wcf rest. wcf restful service file upload multi-platform support works me when uploading single file, when try
[webinvoke(method = "post", uritemplate = "fileupload/{file1name};{file2name}")] it fails. question is: how put 2 arguments uri?
thanks in advance, jp
the answer linked question deals uploading single file - , that's simple, because service read entire http request body, , bound stream parameter. when you're dealing 2 (or more files) doesn't work - need delimiter able know when 1 file ends , other starts. there few media types handle (multipart/* being common), they're not supported natively in wcf (you'd either need create custom formatter deal it, or take whole body stream , split files in fileupload operation).
now assuming have way receive 2 files in request body, can go specific question. uri template feature allows pass multiple parameters, cannot in same "part" of uri path. 1 option split them in multiple parts:
[webinvoke(uritemplate = "fileupload/{file1name}/{file2name}")] or use query parameters that:
[webinvoke(uritemplate = "fileupload?file1={file1name}&file2={file2name}")] that should job. alternative, since have split files on input stream anyway, use format allows specify names in stream itself. example, 1 alternative:
<length of first file name, in bytes> <first filename> <length of first file, in bytes> <bytes corresponding first file> <length of second file name, in bytes> <second filename> <length of second file, in bytes> <bytes corresponding second file> 00 (or other value indicating end of files) there many others (including multipart/*), , in of them you'll need somehow parse input take multiple files apart.
Comments
Post a Comment