3

I am writing a small image/video upload program using WCF REST. Ideally, I would have my service accepting a stream. But the client side developer told me that it would make his life more complicated and he would only pass me a byte array.

I have no idea how to write a REST service that receives a byte array instead of stream. All the examples I could find online are using stream.

Please help!

1 Answer 1

4

Don't worry, he can send a byte array and you can receive a stream. HTTP does not care.

Sign up to request clarification or add additional context in comments.

5 Comments

Just preempting, but is that really a solid answer?: is there any configuration required for this or would WCF by default give you a Stream for instance?
@KierenJohnstone As long as the image is below the standard 64K buffer size, it should just work. You need to change to Streamed mode for transfers bigger than that. The point is, if you are doing REST the only thing the client and server need to agree on is the media type. What type is used for getting the bytes on the wire should be irrelevant.
Would this also work for videos? The service is expecting small video files, around 5MB mostly. The developer is going to send me a 5MB byte array, all in one chunk.
@YoYoMyo Yes, video or image it doesn't matter. However with WCF for that size you need to enabled streamed TransferMode and you will need to increase the MaxReceivedMessageSize property. There are plenty of related questions here on SO.
My blog post shows how to upload large files. bizcoder.com/index.php/2012/01/09/…. Just use ByteArrayContent instead of FileContent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.