Exemplo n.º 1
0
        // Build upload request for file with its corresponding metadata
        private UploadFileWithMetaDataRequest buildUploadFileRequest(FileMetaData metadata)
        {
            var urlParameters = new Dictionary <string, string>();

            urlParameters.Add("appKey", ((KinveyClientRequestInitializer)client.RequestInitializer).AppKey);

            string mode = "POST";

            if (metadata.id != null && metadata.id.Length > 0)
            {
                mode = "PUT";
            }

            // set mimetype for GCS upload
            if (string.IsNullOrEmpty(metadata.mimetype))
            {
                metadata.mimetype = "application/octet-stream";
            }

            UploadFileWithMetaDataRequest uploadRequest = new UploadFileWithMetaDataRequest(metadata, mode, urlParameters, this.client);

            client.InitializeRequest(uploadRequest);
            uploadRequest.customRequestHeaders = this.GetCustomRequestProperties();

            return(uploadRequest);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Upload the specified stream to Kinvey file storage.  The FileMetaData contains extra data about the file.
        /// </summary>
        /// <param name="metadata">Metadata associated with the file; supports arbitrary key/value pairs.</param>
        /// <param name="content">The stream of file content to upload.</param>
        /// <param name="ct">[optional] The cancellation token.  If cancellation is requested, an OperationCancelledException will be thrown.</param>
        public async Task <FileMetaData> uploadAsync(FileMetaData metadata, Stream content, CancellationToken ct = default(CancellationToken))
        {
            UploadFileWithMetaDataRequest uploadRequest = buildUploadFileRequest(metadata);

            ct.ThrowIfCancellationRequested();
            FileMetaData fmd = await uploadRequest.ExecuteAsync();

            ct.ThrowIfCancellationRequested();
            await uploadRequest.uploadFileAsync(fmd, content);

            return(fmd);
        }