开发者

Uploading with multipart/form-data using OpenRasta and IMultipartHttpEntity

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜