public static void UploadFile(Stream postedStream, string fileName, string uploadURL, string fileGroup, string fileType, string specialPath, UploadMethod method) { HttpUploader.UploadFile(postedStream, fileName, uploadURL, fileGroup, fileType, specialPath, Environment.UserName, method); }
/// <summary> /// Upload File to Request Share /// </summary> /// <example> /// POST https://account.sf-api.com/sf/v3/Shares(id)/Upload2 /// { /// "Method":"Method", /// "Raw": false, /// "FileName":"FileName" /// "FileLength": length /// } /// </example> /// <remarks> /// Prepares the links for uploading files to the target Share. /// This method returns an Upload Specification object. The fields are /// populated based on the upload method, provider, and resume parameters passed to the /// upload call. /// The Method determines how the URLs must be called. /// /// Standard uploads use a single HTTP POST message to the ChunkUri address provided in /// the response. All other fields will be empty. Standard uploads do not support Resume. /// /// Streamed uploads use multiple HTTP POST calls to the ChunkUri address. The client must /// append the parameters index, offset and hash to the end of the ChunkUri address. Index /// is a sequential number representing the data block (zero-based); Offset represents the /// byte offset for the block; and hash contains the MD5 hash of the block. The last HTTP /// POST must also contain finish=true parameter. /// /// Threaded uploads use multiple HTTP POST calls to ChunkUri, and can have a number of /// threads issuing blocks in parallel. Clients must append index, offset and hash to /// the end of ChunkUri, as explained in Streamed. After all chunks were sent, the client /// must call the FinishUri provided in this spec. /// /// For all uploaders, the contents of the POST Body can either be "raw", if the "Raw" parameter /// was provided to the Uploader, or use MIME multi-part form encoding otherwise. Raw uploads /// simply put the block content in the POST body - Content-Length specifies the size. Multi-part /// form encoding has to pass the File as a Form parameter named "File1". /// /// For streamed and threaded, if Resume options were provided to the Upload call, then the /// fields IsResume, ResumeIndex, ResumeOffset and ResumeFileHash MAY be populated. If they are, /// it indicates that the server has identified a partial upload with that specification, and is /// ready to resume on the provided parameters. The clients can then verify the ResumeFileHash to /// ensure the file has not been modified; and continue issuing ChunkUri calls from the ResumeIndex /// ResumeOffset parameters. If the client decides to restart, it should simply ignore the resume /// parameters and send the blocks from Index 0. /// /// For all uploaders: the result code for the HTTP POST calls to Chunk and Finish Uri can either /// be a 401 - indicating authentication is required; 4xx/5xx indicating some kind of error; or /// 200 with a Content Body of format 'ERROR:message'. Successful calls will return either a 200 /// response with no Body, or with Body of format 'OK'. /// </remarks> /// <param name="url"></param> /// <param name="method"></param> /// <param name="raw"></param> /// <param name="fileName"></param> /// <param name="fileSize"></param> /// <param name="batchId"></param> /// <param name="batchLast"></param> /// <param name="canResume"></param> /// <param name="startOver"></param> /// <param name="unzip"></param> /// <param name="tool"></param> /// <param name="overwrite"></param> /// <param name="title"></param> /// <param name="details"></param> /// <param name="isSend"></param> /// <param name="sendGuid"></param> /// <param name="opid"></param> /// <param name="threadCount"></param> /// <param name="responseFormat"></param> /// <param name="notify"></param> /// <returns> /// an Upload Specification element, containing the links for uploading, and the parameters for resume. /// The caller must know the protocol for sending the prepare, chunk and finish URLs returned in the spec; as well as /// negotiate the resume upload. /// </returns> public IQuery <UploadSpecification> Upload(Uri url, UploadMethod method = UploadMethod.Standard, bool raw = false, string fileName = null, long fileSize = 0, string batchId = null, bool batchLast = false, bool canResume = false, bool startOver = false, bool unzip = false, string tool = "apiv3", bool overwrite = false, string title = null, string details = null, bool isSend = false, string sendGuid = null, string opid = null, int threadCount = 4, string responseFormat = "json", bool notify = false, DateTime?clientCreatedDateUTC = null, DateTime?clientModifiedDateUTC = null, int?expirationDays = null) { var sfApiQuery = new ShareFile.Api.Client.Requests.Query <UploadSpecification>(Client); sfApiQuery.Action("Upload"); sfApiQuery.Uri(url); sfApiQuery.QueryString("method", method); sfApiQuery.QueryString("raw", raw); sfApiQuery.QueryString("fileName", fileName); sfApiQuery.QueryString("fileSize", fileSize); sfApiQuery.QueryString("batchId", batchId); sfApiQuery.QueryString("batchLast", batchLast); sfApiQuery.QueryString("canResume", canResume); sfApiQuery.QueryString("startOver", startOver); sfApiQuery.QueryString("unzip", unzip); sfApiQuery.QueryString("tool", tool); sfApiQuery.QueryString("overwrite", overwrite); sfApiQuery.QueryString("title", title); sfApiQuery.QueryString("details", details); sfApiQuery.QueryString("isSend", isSend); sfApiQuery.QueryString("sendGuid", sendGuid); sfApiQuery.QueryString("opid", opid); sfApiQuery.QueryString("threadCount", threadCount); sfApiQuery.QueryString("responseFormat", responseFormat); sfApiQuery.QueryString("notify", notify); sfApiQuery.QueryString("clientCreatedDateUTC", clientCreatedDateUTC); sfApiQuery.QueryString("clientModifiedDateUTC", clientModifiedDateUTC); sfApiQuery.QueryString("expirationDays", expirationDays); sfApiQuery.HttpMethod = "POST"; return(sfApiQuery); }
public async void Upload(UploadMethod uploadMethod, int megabytes, bool useAsync, bool useNonAsciiFilename) { var shareFileClient = GetShareFileClient(); var rootFolder = shareFileClient.Items.Get().Execute(); var testFolder = new Folder { Name = RandomString(30) + ".txt" }; testFolder = shareFileClient.Items.CreateFolder(rootFolder.url, testFolder).Execute(); var file = GetFileToUpload(1024 * 1024 * megabytes, useNonAsciiFilename); var uploadSpec = new UploadSpecificationRequest(file.Name, file.Length, testFolder.url, uploadMethod); UploaderBase uploader; if (useAsync) { uploader = shareFileClient.GetAsyncFileUploader(uploadSpec, file); } else { uploader = shareFileClient.GetFileUploader(uploadSpec, file); } var progressInvocations = 0; var bytesTransferred = 0L; uploader.OnTransferProgress += (sender, args) => { bytesTransferred = args.Progress.BytesTransferred; progressInvocations++; }; UploadResponse uploadResponse; if (useAsync) { uploadResponse = await ((AsyncUploaderBase)uploader).UploadAsync(); } else { uploadResponse = ((SyncUploaderBase)uploader).Upload(); } shareFileClient.Items.Delete(testFolder.url); uploadResponse.FirstOrDefault().Should().NotBeNull(); var expectedInvocations = Math.Ceiling((double)file.Length / UploaderBase.DefaultBufferLength) + 1; bytesTransferred.Should().Be(1024 * 1024 * megabytes); if (uploadMethod == UploadMethod.Standard) { progressInvocations.Should().Be((int)expectedInvocations, "Standard should be predictable for number of progress callbacks"); } else if (uploadMethod == UploadMethod.Threaded) { progressInvocations.Should() .BeLessOrEqualTo( (int)expectedInvocations, "Threaded scales, therefore byte ranges vary and are less predictable. We should see no more expectedInvoations"); } }
public static void UploadFile(Stream postedStream, string fileName, string uploadURL, string fileGroup, string fileType, string specialPath, string userName, UploadMethod method) { string uploadType = GetUploadType(method); HttpUploader.UploadFile(postedStream, fileName, uploadURL, fileGroup, fileType, specialPath, userName, uploadType); }
public PrimaryKeyViewModel() { ErrorList = new List <Error>(); VariableLableList = new List <ListViewItem>(); PrimaryKeysList = new List <ListViewItem>(); PK_Id_List = new List <long>(); IsUnique = false; UploadMethod = UploadMethod.Update; }
public JsonResult SetUploadMethod(UploadMethod uploadMethod) { TaskManager = (BExIS.Dcm.UploadWizard.TaskManager)Session["TaskManager"]; if (TaskManager != null) { TaskManager.AddToBus(TaskManager.UPLOAD_METHOD, uploadMethod); } return(Json(true)); }
private static string GetUploadType(UploadMethod method) { string type = "ADD"; switch (method) { case UploadMethod.Add: type = "ADD"; break; case UploadMethod.Update: type = "UPDATE"; break; } return(type); }
public DataApiHelper(Dataset dataset, User user, DataApiModel data, string title, UploadMethod uploadMethod) { datasetManager = new DatasetManager(); userManager = new UserManager(); entityPermissionManager = new EntityPermissionManager(); dataStructureManager = new DataStructureManager(); uploadHelper = new UploadHelper(); _dataset = dataset; _user = user; _data = data; _title = title; _uploadMethod = uploadMethod; _dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(_dataset.DataStructure.Id); reader = new AsciiReader(_dataStructure, new AsciiFileReaderInfo()); }
public static void UploadFile(string uploadURL, string fileGroup, string fileType, string filePath, string newFileName, string specialPath, string userName, UploadMethod method) { string uploadType = GetUploadType(method); HttpUploader.UploadInternalNewFileName(uploadURL, fileGroup, fileType, filePath, newFileName, specialPath, userName, uploadType); }
public static void UploadFile(string uploadURL, string fileGroup, string fileType, string filePath, string specialPath, UploadMethod method) { HttpUploader.UploadFile(uploadURL, fileGroup, fileType, filePath, specialPath, Environment.UserName, method); }
/// <summary> /// Method used to upload videos to a specific user account in Azure Video Indexer. /// Once a video is successfully uploaded, VI automatically indexes it to extract insights. /// When uploading your video based on the URL (preferred) the endpoint must be secured with TLS 1.2 (or higher). /// The upload size with the URL option is limited to 30GB. /// The upload size with the byte array option is limited to 2GB. /// Video Indexer has a max duration limit of 4 hours for a single file. /// Docs: https://docs.microsoft.com/en-us/azure/media-services/video-indexer/upload-index-videos. /// </summary> /// <param name="name">The video's name. A name of the video must be no greater than 80 characters.</param> /// <param name="ispublic">Set to true for public videos, false for private.</param> /// <param name="desc">Description of the video.</param> /// <param name="videoUrl">The location of the video file. For the public url upload method, the URL needs to be encoded.</param> /// <param name="method">Specifies which method to use. See enum comments for details on available options.</param> /// <returns>HTTP request result.</returns> public async Task <string> UploadVideoAsync(string name, bool ispublic, string desc, System.Uri videoUrl, UploadMethod method) { // Validate parameters first if (name?.Length == 0) { throw new ArgumentException(VideoIndexerErrorMessageEmptyVideoName); } if (videoUrl != null && videoUrl.IsWellFormedOriginalString()) { throw new ArgumentException(VideoIndexerErrorMessageInvalidUrl); } MultipartFormDataContent content = new MultipartFormDataContent(); // The parameters of the video. This is only a partial list for now. For the full list, see: // https://api-portal.videoindexer.ai/docs/services/Operations/operations/Upload-Video. string queryParams = CreateQueryString( new Dictionary <string, string>() { // Required. Should be given as parameter in URL query string or in Authorization header as Bearer token, // and match the authorization scope of the call (Account, with Write). // Note that Access tokens expire within 1 hour. { "accessToken", this.accountAccessToken }, // The name of the video. { "name", name }, // The video description. { "description", desc }, // The video privacy mode. Allowed values: Private/Public. { "privacy", ispublic ? "public" : "private" }, // A partition to partition videos by (used for searching a specific partition). // TODO: Allow parameter to set the partition. Fixed for now. { "partition", "partition" }, }); switch (method) { case UploadMethod.LocalFile: // TODO: Implement gradual multipart upload to allow for larger files than 2GB. // FileStream video = File.OpenRead(videoUrl.ToString()); // byte[] buffer =new byte[video.Length]; // video.Read(buffer, 0, buffer.Length); // This is limited to 4.2GB files, but VI doesn't allow for byte array uploads bigger than 2GB. byte[] videodata = File.ReadAllBytes(videoUrl?.LocalPath); content.Add(new ByteArrayContent(videodata)); break; case UploadMethod.PublicUrl: queryParams += $"&videoUrl={videoUrl}"; break; case UploadMethod.SendToBlobStorage: break; default: break; } Uri requestUri = new Uri($"{VideoIndexerApiUrl}/{this.accountLocation}/Accounts/{this.accountId}/Videos?{queryParams}"); var uploadRequestResult = await client.PostAsync(requestUri, content).ConfigureAwait(false); content.Dispose(); return(await uploadRequestResult.Content.ReadAsStringAsync().ConfigureAwait(false)); }
/// <summary> /// Upload File to Request Share /// </summary> /// <example> /// POST https://account.sf-api.com/sf/v3/Shares(id)/Upload2 /// { /// "Method":"Method", /// "Raw": false, /// "FileName":"FileName" /// "FileLength": length /// } /// </example> /// <remarks> /// Prepares the links for uploading files to the target Share. /// This method returns an Upload Specification object. The fields are /// populated based on the upload method, provider, and resume parameters passed to the /// upload call. /// The Method determines how the URLs must be called. /// /// Standard uploads use a single HTTP POST message to the ChunkUri address provided in /// the response. All other fields will be empty. Standard uploads do not support Resume. /// /// Streamed uploads use multiple HTTP POST calls to the ChunkUri address. The client must /// append the parameters index, offset and hash to the end of the ChunkUri address. Index /// is a sequential number representing the data block (zero-based); Offset represents the /// byte offset for the block; and hash contains the MD5 hash of the block. The last HTTP /// POST must also contain finish=true parameter. /// /// Threaded uploads use multiple HTTP POST calls to ChunkUri, and can have a number of /// threads issuing blocks in parallel. Clients must append index, offset and hash to /// the end of ChunkUri, as explained in Streamed. After all chunks were sent, the client /// must call the FinishUri provided in this spec. /// /// For all uploaders, the contents of the POST Body can either be "raw", if the "Raw" parameter /// was provided to the Uploader, or use MIME multi-part form encoding otherwise. Raw uploads /// simply put the block content in the POST body - Content-Length specifies the size. Multi-part /// form encoding has to pass the File as a Form parameter named "File1". /// /// For streamed and threaded, if Resume options were provided to the Upload call, then the /// fields IsResume, ResumeIndex, ResumeOffset and ResumeFileHash MAY be populated. If they are, /// it indicates that the server has identified a partial upload with that specification, and is /// ready to resume on the provided parameters. The clients can then verify the ResumeFileHash to /// ensure the file has not been modified; and continue issuing ChunkUri calls from the ResumeIndex /// ResumeOffset parameters. If the client decides to restart, it should simply ignore the resume /// parameters and send the blocks from Index 0. /// /// For all uploaders: the result code for the HTTP POST calls to Chunk and Finish Uri can either /// be a 401 - indicating authentication is required; 4xx/5xx indicating some kind of error; or /// 200 with a Content Body of format 'ERROR:message'. Successful calls will return either a 200 /// response with no Body, or with Body of format 'OK'. /// </remarks> /// <param name="url"></param> /// <param name="method"></param> /// <param name="raw"></param> /// <param name="fileName"></param> /// <param name="fileSize"></param> /// <param name="batchId"></param> /// <param name="batchLast"></param> /// <param name="canResume"></param> /// <param name="startOver"></param> /// <param name="unzip"></param> /// <param name="tool"></param> /// <param name="overwrite"></param> /// <param name="title"></param> /// <param name="details"></param> /// <param name="isSend"></param> /// <param name="sendGuid"></param> /// <param name="opid"></param> /// <param name="threadCount"></param> /// <param name="responseFormat"></param> /// <param name="notify"></param> /// <returns> /// an Upload Specification element, containing the links for uploading, and the parameters for resume. /// The caller must know the protocol for sending the prepare, chunk and finish URLs returned in the spec; as well as /// negotiate the resume upload. /// </returns> public IQuery<UploadSpecification> Upload(Uri url, UploadMethod method = UploadMethod.Standard, bool raw = false, string fileName = null, long fileSize = 0, string batchId = null, bool batchLast = false, bool canResume = false, bool startOver = false, bool unzip = false, string tool = "apiv3", bool overwrite = false, string title = null, string details = null, bool isSend = false, string sendGuid = null, string opid = null, int threadCount = 4, string responseFormat = "json", bool notify = false, DateTime? clientCreatedDateUTC = null, DateTime? clientModifiedDateUTC = null, int? expirationDays = null) { var sfApiQuery = new ShareFile.Api.Client.Requests.Query<UploadSpecification>(Client); sfApiQuery.Action("Upload"); sfApiQuery.Uri(url); sfApiQuery.QueryString("method", method); sfApiQuery.QueryString("raw", raw); sfApiQuery.QueryString("fileName", fileName); sfApiQuery.QueryString("fileSize", fileSize); sfApiQuery.QueryString("batchId", batchId); sfApiQuery.QueryString("batchLast", batchLast); sfApiQuery.QueryString("canResume", canResume); sfApiQuery.QueryString("startOver", startOver); sfApiQuery.QueryString("unzip", unzip); sfApiQuery.QueryString("tool", tool); sfApiQuery.QueryString("overwrite", overwrite); sfApiQuery.QueryString("title", title); sfApiQuery.QueryString("details", details); sfApiQuery.QueryString("isSend", isSend); sfApiQuery.QueryString("sendGuid", sendGuid); sfApiQuery.QueryString("opid", opid); sfApiQuery.QueryString("threadCount", threadCount); sfApiQuery.QueryString("responseFormat", responseFormat); sfApiQuery.QueryString("notify", notify); sfApiQuery.QueryString("clientCreatedDateUTC", clientCreatedDateUTC); sfApiQuery.QueryString("clientModifiedDateUTC", clientModifiedDateUTC); sfApiQuery.QueryString("expirationDays", expirationDays); sfApiQuery.HttpMethod = "POST"; return sfApiQuery; }
public UploadSpecificationRequest(string fileName, long fileSize, Uri parent, UploadMethod method) : this(fileName, fileSize, parent) { Method = method; }
public async void Upload(UploadMethod uploadMethod, int megabytes, bool useAsync) { var shareFileClient = GetShareFileClient(); var rootFolder = shareFileClient.Items.Get().Execute(); var testFolder = new Folder { Name = RandomString(30) + ".txt" }; testFolder = shareFileClient.Items.CreateFolder(rootFolder.url, testFolder).Execute(); var file = GetFileToUpload(1024 * 1024 * megabytes); var uploadSpec = new UploadSpecificationRequest(file.Name, file.Length, testFolder.url, uploadMethod); UploaderBase uploader; if (useAsync) { uploader = shareFileClient.GetAsyncFileUploader(uploadSpec, file); } else { uploader = shareFileClient.GetFileUploader(uploadSpec, file); } var progressInvocations = 0; var bytesTransferred = 0L; uploader.OnTransferProgress += (sender, args) => { bytesTransferred = args.Progress.BytesTransferred; progressInvocations++; }; UploadResponse uploadResponse; if (useAsync) { uploadResponse = await((AsyncUploaderBase)uploader).UploadAsync(); } else { uploadResponse = ((SyncUploaderBase)uploader).Upload(); } shareFileClient.Items.Delete(testFolder.url); uploadResponse.FirstOrDefault().Should().NotBeNull(); var expectedInvocations = Math.Ceiling((double)file.Length / UploaderBase.DefaultBufferLength) + 1; bytesTransferred.Should().Be(1024 * 1024 * megabytes); if (uploadMethod == UploadMethod.Standard) { progressInvocations.Should().Be((int)expectedInvocations, "Standard should be predictable for number of progress callbacks"); } else if (uploadMethod == UploadMethod.Threaded) { progressInvocations.Should() .BeLessOrEqualTo( (int)expectedInvocations, "Threaded scales, therefore byte ranges vary and are less predictable. We should see no more expectedInvoations"); } }