/// <summary>
        /// This action takes a MIME multipart file upload and stores the result in 
        /// the Azure cloud store. Both the reading and writing of the blob happens
        /// asynchronously without blocking any threads.
        /// </summary>
        public async Task<Collection<AzureBlobInfo>> Post()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            // Get or create the blob container
            CloudBlobContainer container = await _blobContainer.Value;

            // Create a AzureBlobStorageMultipartProvider and process the request
            AzureBlobStorageMultipartProvider streamProvider = new AzureBlobStorageMultipartProvider(container, Path.GetTempPath());
            await Request.Content.ReadAsMultipartAsync<AzureBlobStorageMultipartProvider>(streamProvider);

            // Return result from storing content in the blob container
            return streamProvider.AzureBlobs;
        }
Exemplo n.º 2
0
        /// <summary>
        /// This action takes a MIME multipart file upload and stores the result in
        /// the Azure cloud store. Both the reading and writing of the blob happens
        /// asynchronously without blocking any threads.
        /// </summary>
        public async Task <Collection <AzureBlobInfo> > Post()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            // Get or create the blob container
            CloudBlobContainer container = await _blobContainer.Value;

            // Create a AzureBlobStorageMultipartProvider and process the request
            AzureBlobStorageMultipartProvider streamProvider = new AzureBlobStorageMultipartProvider(container, Path.GetTempPath());
            await Request.Content.ReadAsMultipartAsync <AzureBlobStorageMultipartProvider>(streamProvider);

            // Return result from storing content in the blob container
            return(streamProvider.AzureBlobs);
        }
        public async Task <IEnumerable <string> > PostUpload(string category)
        {
            // Check whether it is an HTML form file upload request
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                // return UnsupportedMediaType response back if not
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.UnsupportedMediaType));
            }

            //MultipartFormDataStreamProvider multipartFormDataStreamProvider = new CustomMultipartFormDataStreamProvider(@"C:\Trash");
            //await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);
            //return multipartFormDataStreamProvider.FileData.Select(entry => entry.LocalFileName);

            CloudBlobContainer container = await GetCloudBlobContainer(category.ToSlug());

            AzureBlobStorageMultipartProvider provider = new AzureBlobStorageMultipartProvider(container);
            await Request.Content.ReadAsMultipartAsync(provider);

            return(provider.AzureBlobs.Select(entry => entry.Location));
        }
        public Task <List <FileDetails> > Post()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            var multipartStreamProvider = new AzureBlobStorageMultipartProvider(BlobHelper.GetWebApiContainer());

            return(Request.Content.ReadAsMultipartAsync <AzureBlobStorageMultipartProvider>(multipartStreamProvider).ContinueWith <List <FileDetails> >(t =>
            {
                if (t.IsFaulted)
                {
                    throw t.Exception;
                }

                AzureBlobStorageMultipartProvider provider = t.Result;
                return provider.Files;
            }));
        }
Exemplo n.º 5
0
        public Task <List <FileDetails> > UploadFile(string containerName)
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            CloudBlobContainer postingContainer = containerInteractor.GetContainerByName(containerName)
                                                  ?? containerInteractor.CreateNewContainer(containerName);

            var multipartStreamProvider = new AzureBlobStorageMultipartProvider(postingContainer);

            return(Request.Content.ReadAsMultipartAsync(multipartStreamProvider)
                   .ContinueWith(t =>
            {
                if (t.IsFaulted)
                {
                    throw t.Exception;
                }

                AzureBlobStorageMultipartProvider provider = t.Result;
                return provider.Files;
            }));
        }
        public async Task <string> PostDumpChunk(string owner, string targetos, int index, ulong filesize, string displayName = "")
        {
            if (index > 0 || filesize > int.MaxValue)
            {
                throw new NotSupportedException("We do not support chunked files yet, and the file must be <= 2GB or more specifically, int.MaxValue");
            }

            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            owner    = owner.ToLowerInvariant();
            targetos = targetos.ToLowerInvariant();

            await DumplingEventHub.FireEvent(new WebAPIStartUploadChunkEvent());

            /* Handle Upload */
            // Get or create the blob container
            var container = DumpStorageController.GetContainerForOwner(owner);
            await container.CreateIfNotExistsAsync();

            // Create a AzureBlobStorageMultipartProvider and process the request
            var path = Path.GetTempPath();
            AzureBlobStorageMultipartProvider streamProvider = new AzureBlobStorageMultipartProvider(container, path);

            await Request.Content.ReadAsMultipartAsync <AzureBlobStorageMultipartProvider>(streamProvider);

            await DumplingEventHub.FireEvent(new WebAPIFinishedUploadChunkEvent());

            /* Meta data handling */
            var dump_uri = streamProvider.AzureBlobs.First().Location;

            if (displayName == string.Empty)
            {
                displayName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
            }

            int dumplingid = await TriageDb.AddDumpAsync(new Dump()
            {
                DumpTime    = DateTime.Now,
                DumpPath    = dump_uri,
                DisplayName = displayName,
                Origin      = owner
            });


            StateTableIdentifier id = new StateTableIdentifier()
            {
                Owner      = owner,
                DumplingId = dumplingid.ToString(),
            };

            await AnalysisTopicController.EnqueueAnalysisWork(owner, dumplingid.ToString(), targetos, dump_uri);

            // let the dumpling services know about our dumpling
            await StateTableController.AddOrUpdateStateEntry(new StateTableEntity(id)
            {
                DumpRelics_uri = dump_uri,
                OriginatingOS  = targetos,
                State          = "enqueued"
            });

            // Return result from storing content in the blob container
            return(dumplingid.ToString());
        }