Inheritance: CloudinaryDotNet.Actions.ImageUploadParams
示例#1
0
        /// <summary>
        /// Uploads a video file to cloudinary.
        /// </summary>
        /// <param name="parameters">Parameters of video uploading .</param>
        /// <returns>Results of video uploading.</returns>
        public VideoUploadResult Upload(VideoUploadParams parameters)
        {
            string uri = m_api.ApiUrlVideoUpV.BuildUrl();

            ResetInternalFileDescription(parameters.File);

            using (HttpWebResponse response = m_api.Call(HttpMethod.POST, uri, parameters.ToParamsDictionary(), parameters.File))
            {
                return VideoUploadResult.Parse(response);
            }
        }
示例#2
0
		public VideoUploadResult UploadLargeVideo(VideoUploadParams parameters, int bufferSize = 20 * 1024 * 1024)
		{
			if (parameters.File.IsRemote)
				throw new ArgumentException("The UploadLargeRaw method is intended to be used for large local file uploading and can't be used for remote file uploading!");

			string uri = m_api.ApiUrlV.Action("upload_large").ResourceType("video").BuildUrl();

			ResetInternalFileDescription(parameters.File, bufferSize);

			int partNumber = 1;
			string publicId = null;
			string uploadId = null;

			VideoUploadResult result = null;

			while (!parameters.File.EOF)
			{
				var dict = parameters.ToParamsDictionary();

				dict.Add("part_number", partNumber);

				if (partNumber > 1)
				{
					dict["public_id"] = publicId;
					dict["upload_id"] = uploadId;
				}

				if (parameters.File.IsLastPart())
					dict["final"] = true;

				using (HttpWebResponse response = m_api.Call(HttpMethod.POST, uri, dict, parameters.File))
				{
					var partResult = VideoPartUploadResult.Parse(response);
					result = partResult;

					if (result.StatusCode != HttpStatusCode.OK)
						throw new WebException(String.Format(
							"An error has occured while uploading file (status code: {0}). {1}",
							partResult.StatusCode,
							partResult.Error != null ? partResult.Error.Message : "Unknown error"));

					if (partNumber == 1)
					{
						publicId = partResult.PublicId;
						uploadId = partResult.UploadId;
					}

					partNumber++;
				}
			}

			return result;
		}
示例#3
0
        public void TestUploadLocalVideo()
        {
            var uploadParams = new VideoUploadParams()
            {
                File = new FileDescription(m_testVideoPath)
            };

            var uploadResult = m_cloudinary.Upload(uploadParams);

            Assert.AreEqual(640, uploadResult.Width);
            Assert.AreEqual(320, uploadResult.Height);
            Assert.AreEqual("mp4", uploadResult.Format);
            Assert.NotNull(uploadResult.Audio);
            Assert.AreEqual("aac", uploadResult.Audio.Codec);
            Assert.NotNull(uploadResult.Video);
            Assert.AreEqual("h264", uploadResult.Video.Codec);

            var getResource = new GetResourceParams(uploadResult.PublicId) { ResourceType = ResourceType.Video };
            var info = m_cloudinary.GetResource(getResource);

            Assert.AreEqual("mp4", info.Format);
        }
        public void TestLargeUploadLocalVideoWithTransformation()
        {
            var uploadParams = new VideoUploadParams()
            {
                File = new FileDescription(m_testLargeVideoPath),
                EagerAsync = true,
                EagerTransforms = new List<Transformation>
                {
                    //Transforming mp4 to webm
                    new EagerTransformation { Format = "webm" }
                }
            };

            var uploadResult = m_cloudinary.UploadLargeVideo(uploadParams);

            Assert.AreEqual(1280, uploadResult.Width);
            Assert.AreEqual(720, uploadResult.Height);
            Assert.AreEqual("mp4", uploadResult.Format);
        }