Esempio n. 1
0
 public CommonChunkedUploadSession Get(string sessionId)
 {
     using (var stream = DataStore.GetReadStream(Domain, GetPathWithId(sessionId)))
     {
         return(CommonChunkedUploadSession.Deserialize(stream));
     }
 }
Esempio n. 2
0
        public Stream UploadSingleChunk(CommonChunkedUploadSession uploadSession, Stream stream, long chunkLength)
        {
            if (uploadSession.BytesTotal == 0)
            {
                uploadSession.BytesTotal = chunkLength;
            }

            if (uploadSession.BytesTotal >= chunkLength)
            {
                //This is hack fixing strange behaviour of plupload in flash mode.

                if (string.IsNullOrEmpty(uploadSession.ChunksBuffer))
                {
                    uploadSession.ChunksBuffer = TempPath.GetTempFileName();
                }

                using (var bufferStream = new FileStream(uploadSession.ChunksBuffer, FileMode.Append))
                {
                    stream.CopyTo(bufferStream);
                }

                uploadSession.BytesUploaded += chunkLength;

                if (uploadSession.BytesTotal == uploadSession.BytesUploaded)
                {
                    return(new FileStream(uploadSession.ChunksBuffer, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite,
                                          4096, FileOptions.DeleteOnClose));
                }
            }

            return(Stream.Null);
        }
Esempio n. 3
0
 public void Store(CommonChunkedUploadSession s)
 {
     using (var stream = s.Serialize())
     {
         DataStore.SavePrivate(Domain, GetPathWithId(s.Id), stream, s.Expired);
     }
 }
Esempio n. 4
0
        public void Finalize(CommonChunkedUploadSession uploadSession)
        {
            var tempPath = uploadSession.TempPath;
            var uploadId = uploadSession.UploadId;
            var eTags    = uploadSession.GetItemOrDefault <List <string> >("ETag")
                           .Select((x, i) => new KeyValuePair <int, string>(i + 1, x))
                           .ToDictionary(x => x.Key, x => x.Value);

            DataStore.FinalizeChunkedUpload(Domain, tempPath, uploadId, eTags);
        }
Esempio n. 5
0
        public void Abort(CommonChunkedUploadSession uploadSession)
        {
            if (uploadSession.UseChunks)
            {
                var tempPath = uploadSession.TempPath;
                var uploadId = uploadSession.UploadId;

                DataStore.AbortChunkedUpload(Domain, tempPath, uploadId);
            }
            else if (!string.IsNullOrEmpty(uploadSession.ChunksBuffer))
            {
                File.Delete(uploadSession.ChunksBuffer);
            }
        }
Esempio n. 6
0
        public void Init(CommonChunkedUploadSession chunkedUploadSession)
        {
            if (chunkedUploadSession.BytesTotal < MaxChunkUploadSize)
            {
                chunkedUploadSession.UseChunks = false;
                return;
            }

            var tempPath = Guid.NewGuid().ToString();
            var uploadId = DataStore.InitiateChunkedUpload(Domain, tempPath);

            chunkedUploadSession.TempPath = tempPath;
            chunkedUploadSession.UploadId = uploadId;
        }
Esempio n. 7
0
        public void UploadChunk(CommonChunkedUploadSession uploadSession, Stream stream, long length)
        {
            var tempPath    = uploadSession.TempPath;
            var uploadId    = uploadSession.UploadId;
            var chunkNumber = uploadSession.GetItemOrDefault <int>("ChunksUploaded") + 1;

            var eTag = DataStore.UploadChunk(Domain, tempPath, uploadId, stream, MaxChunkUploadSize, chunkNumber, length);

            uploadSession.Items["ChunksUploaded"] = chunkNumber;
            uploadSession.BytesUploaded          += length;

            var eTags = uploadSession.GetItemOrDefault <List <string> >("ETag") ?? new List <string>();

            eTags.Add(eTag);
            uploadSession.Items["ETag"] = eTags;
        }
Esempio n. 8
0
 public void Remove(CommonChunkedUploadSession s)
 {
     DataStore.Delete(Domain, GetPathWithId(s.Id));
 }
Esempio n. 9
0
 public void Move(CommonChunkedUploadSession chunkedUploadSession, string newPath, bool quotaCheckFileSize = true)
 {
     DataStore.Move(Domain, chunkedUploadSession.TempPath, string.Empty, newPath, quotaCheckFileSize);
 }
Esempio n. 10
0
 public void Move(CommonChunkedUploadSession chunkedUploadSession, string newPath)
 {
     DataStore.Move(Domain, chunkedUploadSession.TempPath, string.Empty, newPath);
 }