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);
                }));
        }
示例#2
0
        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);
                      }
                );
        }
示例#3
0
 public Blob(BlobInfo info, int length, string url) : this()
 {
     Info = info;
     Length = length;
     Url = url;
 }
示例#4
0
        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);
                      }
                );
        }