Example #1
0
        /// <summary>
        /// Uploads multiple files to the server path
        /// </summary>
        /// <param name="path"></param>
        /// <param name="fileWrapperList"></param>
        /// <returns></returns>
        private async Task <T> UploadFiles <T>(String path, List <FileWrapper> fileWrapperList)
        {
            Uri url = new Uri(path);
            HttpResponseMessage response;

            using (var client = new HttpClient(CreateHttpMessageHandler()))
            {
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Add("Accept", "application/json");
                client.DefaultRequestHeaders.Add("Authorization", await this.GetAuthorizationHeader(null));
                MultipartFormDataContent filesContent = new MultipartFormDataContent("--------------");
                foreach (FileWrapper file in fileWrapperList)
                {
                    Model.File.FileInfo fileInfo = file.Info();

                    var fileContent = new StreamContent(file.EncryptedData());
                    fileContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                    {
                        Name     = "\"" + fileInfo.Name + "\"",
                        FileName = "\"" + fileInfo.Name + "\""
                    };


                    filesContent.Add(fileContent);
                }
                response = await client.PostAsync(url, filesContent);
            }
            return(JsonHelper.ObjectToObject <T>(response.Content.ReadAsStringAsync().Result));
        }
Example #2
0
        /// <summary>
        /// Adds the key info to the fileInfo
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        protected Model.File.FileInfo AddKeyToFileInfo(Model.File.FileInfo info)
        {
            if (this._key == null)
            {
                return(info);
            }

            info.Key = this._key.Export();
            return(info);
        }
Example #3
0
        public override Model.File.FileInfo Info()
        {
            System.IO.FileInfo fl = new System.IO.FileInfo(Path);
            if (!fl.Exists)
            {
                throw new TraceSdkException("Error while loading file " + fl.FullName);
            }

            long   size     = fl.Length;
            string mimetype = Helpers.GetMimeType(Path);
            String name     = fl.Name;

            Stratumn.Sdk.Model.File.FileInfo fileInfo = new Stratumn.Sdk.Model.File.FileInfo(name, size, mimetype, null);

            return(AddKeyToFileInfo(fileInfo));
        }
Example #4
0
        private async Task <List <Property <FileWrapper> > > DownloadFiles(Dictionary <string, Property <FileRecord> > fileRecordMap)
        {
            List <Property <FileWrapper> > fileWrapperList = new List <Property <FileWrapper> >();

            if (fileRecordMap.Count == 0)
            {
                return(fileWrapperList);
            }

            foreach (var fileRecordProp in fileRecordMap)
            {
                FileRecord   fileRecord = fileRecordProp.Value.Value;
                MemoryStream file       = await client.DownloadFile(fileRecord);

                FileInfo info = fileRecord.GetFileInfo();
                // When downloading a file, set disableEncrpytion to true if no key is passed so that the
                // FileWrapper doesn't generate a new key and try to decrypt the file data.
                FileWrapper fileWrapper = new FileBlobWrapper(file, info, info.Key == null || info.Key == "");
                fileWrapperList.Add(fileRecordProp.Value.Transform((T) => fileWrapper));
            }
            return(fileWrapperList);
        }
Example #5
0
 internal FileBlobWrapper(MemoryStream blob, Model.File.FileInfo fileInfo, bool disableEncryption) : base(disableEncryption, fileInfo.Key)
 {
     this.Blob     = blob;
     this.FileInfo = fileInfo;
 }
Example #6
0
 public FileBlobWrapper(MemoryStream blob, Model.File.FileInfo fileInfo) : base(false, fileInfo.Key)
 {
     this.Blob     = blob;
     this.FileInfo = fileInfo;
 }
Example #7
0
 public static FileWrapper FromFileBlob(MemoryStream blob, Model.File.FileInfo fileInfo)
 {
     return(new FileBlobWrapper(blob, fileInfo));
 }
Example #8
0
 public FileBlobWrapper(MemoryStream blob, Model.File.FileInfo fileInfo)
 {
     this.Blob     = blob;
     this.FileInfo = fileInfo;
 }