public IAsyncAction UploadAsync(IRecord record, string contentType, IInputStream stream) { if (record == null) { throw new ArgumentNullException("record"); } return AsyncInfo.Run(cancelToken => Task.Run(async () => { if (string.IsNullOrEmpty(contentType)) { contentType = HttpStreamer.OctetStreamMimeType; } var blobInfo = new BlobInfo(contentType); await record.PutBlobInItem(Item, blobInfo, stream).AsTask(cancelToken); })); }
public IAsyncOperation<ItemKey> PutBlobInItem(RecordItem item, BlobInfo blobInfo, IInputStream source) { item.ValidateRequired("item"); return AsyncInfo.Run( async cancelToken => { Blob blob = await UploadBlob(blobInfo, source).AsTask(cancelToken); item.AddOrUpdateBlob(blob); return await UpdateItemAsync(item).AsTask(cancelToken); } ); }
public Blob(BlobInfo info, int length, string url) : this() { Info = info; Length = length; Url = url; }
public IAsyncOperation<Blob> UploadBlob(BlobInfo blobInfo, IInputStream source) { if (source == null) { throw new ArgumentNullException("source"); } blobInfo.ValidateRequired("blobInfo"); return AsyncInfo.Run( async cancelToken => { Stream stream = source.AsStreamForRead(); Uri blobUri = await Client.RecordMethods.UploadBlobStreamAsync( m_recordRef, stream, blobInfo.ContentType, cancelToken); return new Blob(blobInfo, (int) stream.Length, blobUri.AbsoluteUri); } ); }