/// <inheritdoc/> async Task <AmazonNode> IAmazonFiles.UploadNew(FileUpload fileUpload) { var url = string.Format("{0}nodes", await GetContentUrl().ConfigureAwait(false)); if (fileUpload.AllowDuplicate) { url += "?suppress=deduplication"; } var obj = new NewChild { name = fileUpload.FileName, parents = new string[] { fileUpload.ParentId }, kind = "FILE" }; string meta = JsonConvert.SerializeObject(obj); var file = new SendFileInfo { StreamOpener = fileUpload.StreamOpener, FileName = fileUpload.FileName, FormName = "content", CancellationToken = fileUpload.CancellationToken, BufferSize = fileUpload.BufferSize, Progress = fileUpload.Progress, Parameters = new Dictionary <string, string> { { "metadata", meta } } }; return(await http.SendFile <AmazonNode>(HttpMethod.Post, url, file).ConfigureAwait(false)); }
/// <summary> /// Upload file to folder. /// </summary> /// <param name="parentId">Folder id for new file</param> /// <param name="fileName">Name of new file</param> /// <param name="streamCreator">Func returning Stream for data. Can be called multiple times if retry happened. Stream will be closed by method.</param> /// <param name="allowDuplicate">True to allow duplicate uploads. /// If it's False and file MD5 is the same as some other file in the cloud HTTP error Conflict will be thrown</param> /// <returns>Node info for new file</returns> public async Task <AmazonNode> UploadNew(string parentId, string fileName, Func <Stream> streamCreator, bool allowDuplicate = true) { var url = string.Format("{0}nodes", await amazon.GetContentUrl().ConfigureAwait(false)); if (allowDuplicate) { url += "?suppress=deduplication"; } var obj = new NewChild { name = fileName, parents = new string[] { parentId }, kind = "FILE" }; string meta = JsonConvert.SerializeObject(obj); var file = new FileUpload { StreamOpener = streamCreator, FileName = fileName, FormName = "content", Parameters = new Dictionary <string, string> { { "metadata", meta } } }; return(await http.SendFile <AmazonNode>(HttpMethod.Post, url, file).ConfigureAwait(false)); }
/// <inheritdoc/> async Task<AmazonNode> IAmazonFiles.UploadNew(FileUpload fileUpload) { var url = string.Format("{0}nodes", await GetContentUrl().ConfigureAwait(false)); if (fileUpload.AllowDuplicate) { url += "?suppress=deduplication"; } var obj = new NewChild { name = fileUpload.FileName, parents = new string[] { fileUpload.ParentId }, kind = "FILE" }; var meta = JsonConvert.SerializeObject(obj); var file = new SendFileInfo { StreamOpener = fileUpload.StreamOpener, FileName = fileUpload.FileName, FormName = "content", CancellationToken = fileUpload.CancellationToken, BufferSize = fileUpload.BufferSize, Progress = fileUpload.Progress, Parameters = new Dictionary<string, string> { { "metadata", meta } } }; return await http.SendFile<AmazonNode>(HttpMethod.Post, url, file).ConfigureAwait(false); }
/// <inheritdoc/> async Task <AmazonNode> IAmazonNodes.CreateFolder(string parentId, string name) { var url = string.Format("{0}nodes", await GetMetadataUrl().ConfigureAwait(false)); var folder = new NewChild { name = name, parents = new string[] { parentId }, kind = "FOLDER" }; return(await http.Post <NewChild, AmazonNode>(url, folder).ConfigureAwait(false)); }
private void AttrValue(ref string data, int i = 0) { if (i < data.Length) { if (data[i].ToString() == "'") { NewChild.SetAttribute(AttrcName, attrValue); attrValue = AttrcName = ""; EndOfBeginObject(ref data, i + 1); } else { attrValue += data[i]; AttrValue(ref data, i + 1); } } }
/// <inheritdoc/> async Task <FileUploadResult> IAmazonFiles.UploadNew(FileUpload fileUpload) { /* * var url = string.Format("{0}nodes", await GetContentUrl().ConfigureAwait(false)); * if (fileUpload.AllowDuplicate) * { * url += "?suppress=deduplication"; * } */ var url = BuildMethodUrl("uploadfile"); url = $"{url}&nopartial=1&folderid={fileUpload.ParentId}"; if (fileUpload.AllowDuplicate) { url += "&renameifexists=1"; } var obj = new NewChild { name = fileUpload.FileName, parents = new string[] { fileUpload.ParentId }, kind = "FILE" }; string meta = JsonConvert.SerializeObject(obj); var file = new SendFileInfo { StreamOpener = fileUpload.StreamOpener, FileName = fileUpload.FileName, FormName = "content", CancellationToken = fileUpload.CancellationToken, BufferSize = fileUpload.BufferSize, Progress = fileUpload.Progress, /* Parameters = new Dictionary<string, string> * { * { "metadata", meta } * } */ }; return(await http.SendFile <FileUploadResult>(HttpMethod.Post, url, file).ConfigureAwait(false)); }