开发者

Uploading with multipart/form-data using OpenRasta and IMultipartHttpEntity

开发者 https://www.devze.com 2023-01-25 10:44 出处:网络
I\'m trying to post some files using OpenRasta.I\'ve gotten as far as getting my handler called, but by all appearances the stream in the entity is empty.Here\'s my handler:

I'm trying to post some files using OpenRasta. I've gotten as far as getting my handler called, but by all appearances the stream in the entity is empty. Here's my handler:

public OperationResult Post( IEnumerable<IMultipartHttpEntity> entities)
{
    var foo = entities.ToList();
    foreach (var entity in foo)
    {
        if (entity.Stream != null &开发者_如何学编程;& entity.ContentType != null)
        {
            var memoryStream = new MemoryStream();
            entity.Stream.CopyTo(memoryStream);
        }
    }
    return new OperationResult.Created();
}

Each time through the loop memoryStream has a length of 0. What am I doing wrong?


Nothing like posting on StackOverflow to make the answer immediately obvious. Apparently you only get one enumeration of the entities in order to grab the stream. I had added the "foo" variable above to make debugging easier, but it was causing the streaming to fail. As I stored the stream to the database, I had also failed to reset memoryStream to the beginning before writing it. Fixing these two issues got the file to upload correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消