/// <summary> /// Restores an item that has been moved to the trash. Default behavior is to restore the item to the folder it was in before /// it was moved to the trash. If that parent folder no longer exists or if there is now an item with the same name in that /// parent folder, the new parent folder and/or new name will need to be included in the request. /// </summary> /// <returns>The full item will be returned with a 201 Created status. By default it is restored to the parent folder it was in before it was trashed.</returns> public async Task <BoxFile> RestoreTrashedAsync(BoxFileRequest fileRequest, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); fileRequest.Name.ThrowIfNullOrWhiteSpace("fileRequest.Name"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, fileRequest.Id) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(fileRequest)); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false); return(response.ResponseObject); }
/// <summary> /// Used to update individual or multiple fields in the file object, including renaming the file, changing it’s description, /// and creating a shared link for the file. To move a file, change the ID of its parent folder. An optional etag /// can be included to ensure that client only updates the file if it knows about the latest version. /// </summary> /// <param name="fileRequest">BoxFileRequest object.</param> /// <param name="etag">This ‘etag’ field of the file, which will be set in the If-Match header.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns>The complete BoxFile object.</returns> public async Task <BoxFile> UpdateInformationAsync(BoxFileRequest fileRequest, string etag = null, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, fileRequest.Id) .Method(RequestMethod.Put) .Header(Constants.RequestParameters.IfMatch, etag) .Param(ParamFields, fields); request.Payload = _converter.Serialize(fileRequest); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false); return(response.ResponseObject); }
/// <summary> /// Used to create a copy of a file in another folder. The original version of the file will not be altered. /// </summary> /// <param name="fileRequest"></param> /// <returns></returns> public async Task <BoxFile> CopyAsync(BoxFileRequest fileRequest, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest") .Name.ThrowIfNullOrWhiteSpace("fileRequest.Name"); fileRequest.Parent.ThrowIfNull("fileRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields) .Payload(_converter.Serialize(fileRequest)) .Authorize(_auth.Session.AccessToken); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request); return(response.ResponseObject); }
/// <summary> /// Used to update individual or multiple fields in the file object, including renaming the file, changing it’s description, /// and creating a shared link for the file. To move a file, change the ID of its parent folder. An optional etag /// can be included to ensure that client only updates the file if it knows about the latest version. /// </summary> /// <param name="fileRequest"></param> /// <returns></returns> public async Task <BoxFile> UpdateInformationAsync(BoxFileRequest fileRequest, string etag = null, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, fileRequest.Id) .Method(RequestMethod.Put) .Header("If-Match", etag) .Param(ParamFields, fields) .Authorize(_auth.Session.AccessToken); request.Payload = _converter.Serialize(fileRequest); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request); return(response.ResponseObject); }
/// <summary> /// Uploads a provided file to the target parent folder. /// If the file already exists, an error will be thrown. /// A proper timeout should be provided for large uploads. /// </summary> /// <param name="fileRequest">BoxFileRequest object.</param> /// <param name="stream">Stream of uploading file.</param> /// <param name="fields">Fields which shall be returned in result.</param> /// <param name="timeout">Timeout for response.</param> /// <param name="contentMD5">The SHA1 hash of the file.</param> /// <param name="setStreamPositionToZero">Set position for input stream to 0.</param> /// <param name="uploadUri">Uri to use for upload. Default upload endpoint URI is used if not specified.</param> /// <returns>A full file object is returned inside of a collection if the ID is valid and if the update is successful.</returns> public async Task <BoxFile> UploadAsync(BoxFileRequest fileRequest, Stream stream, List <string> fields = null, TimeSpan?timeout = null, byte[] contentMD5 = null, bool setStreamPositionToZero = true, Uri uploadUri = null) { stream.ThrowIfNull("stream"); fileRequest.ThrowIfNull("fileRequest") .Name.ThrowIfNullOrWhiteSpace("filedRequest.Name"); fileRequest.Parent.ThrowIfNull("fileRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id"); if (setStreamPositionToZero) { stream.Position = 0; } uploadUri = uploadUri == null ? _config.FilesUploadEndpointUri : uploadUri; BoxMultiPartRequest request = new BoxMultiPartRequest(uploadUri) { Timeout = timeout } .Param(ParamFields, fields) .FormPart(new BoxStringFormPart() { Name = "attributes", Value = _converter.Serialize(fileRequest) }) .FormPart(new BoxFileFormPart() { Name = "file", Value = stream, FileName = fileRequest.Name }); if (contentMD5 != null) { request.Header(Constants.RequestParameters.ContentMD5, HexStringFromBytes(contentMD5)); } IBoxResponse <BoxCollection <BoxFile> > response = await ToResponseAsync <BoxCollection <BoxFile> >(request).ConfigureAwait(false); // We can only upload one file at a time, so return the first entry return(response.ResponseObject.Entries.FirstOrDefault()); }
/// <summary> /// Used to create a copy of a file in another folder. The original version of the file will not be altered. /// </summary> /// <param name="fileRequest">BoxFileRequest object.</param> /// <param name="fields">Attribute(s) to include in the response.</param> /// <returns> /// A full file object is returned if the ID is valid and if the update is successful. /// Errors can be thrown if the destination folder is invalid or if a file-name collision occurs. /// </returns> public async Task <BoxFile> CopyAsync(BoxFileRequest fileRequest, List <string> fields = null) { fileRequest.ThrowIfNull("fileRequest"); fileRequest.Id.ThrowIfNullOrWhiteSpace("fileRequest.Id"); fileRequest.Parent.ThrowIfNull("fileRequest.Parent") .Id.ThrowIfNullOrWhiteSpace("fileRequest.Parent.Id"); BoxRequest request = new BoxRequest(_config.FilesEndpointUri, string.Format(Constants.CopyPathString, fileRequest.Id)) .Method(RequestMethod.Post) .Param(ParamFields, fields); fileRequest.Id = null; //file Id was used as a query parameter in this case request.Payload(_converter.Serialize(fileRequest)); IBoxResponse <BoxFile> response = await ToResponseAsync <BoxFile>(request).ConfigureAwait(false); return(response.ResponseObject); }