Beispiel #1
0
        public async Task <ImageUploadResponse> AddAsset(ImageUploadInput arg)
        {
            ImageUploadResponse imageResponse = new ImageUploadResponse();

            try
            {
                using (var uploadStream = arg.Upload.OpenReadStream())
                {
                    fileVerifier.Validate(uploadStream, arg.Upload.FileName, arg.Upload.ContentType);
                    string autoFileFolder = "AutoUploads";
                    var    autoFileFile   = Guid.NewGuid().ToString() + Path.GetExtension(arg.Upload.FileName);
                    var    autoPath       = Path.Combine(autoFileFolder, autoFileFile);
                    using (Stream stream = fileFinder.WriteFile(autoPath))
                    {
                        await uploadStream.CopyToAsync(stream);
                    }

                    imageResponse.Uploaded = 1;
                    imageResponse.FileName = autoFileFile;
                    imageResponse.Url      = pathBase + autoPath.EnsureStartingPathSlash();
                }
            }
            catch (Exception ex)
            {
                imageResponse.Message  = ex.Message;
                imageResponse.Uploaded = 0;
            }

            return(imageResponse);
        }
 public Task <ImageUploadResponse> Asset([FromForm] ImageUploadInput arg)
 {
     return(assetRepo.AddAsset(arg));
 }
Beispiel #3
0
 /// <summary>
 /// Acquire and return an upload lease to s3 temp bucket.
 /// The return value of this function is a json object containing credentials for uploading assets to S3 bucket, S3 url for upload request and the key to use for uploading.
 /// Using this lease the client will upload the emoji image to S3 temp bucket (included as part of the S3 URL). This lease is used by S3 to verify that the upload is authorized.
 /// </summary>
 /// <param name="subreddit">The subreddit with the emojis</param>
 /// <param name="imageUploadInput">A valid ImageUploadInput instance</param>
 /// <returns>An S3 lease.</returns>
 public S3UploadLeaseContainer AcquireLease(string subreddit, ImageUploadInput imageUploadInput)
 {
     return(SendRequest <S3UploadLeaseContainer>("api/v1/" + subreddit + "/emoji_asset_upload_s3.json", imageUploadInput, Method.POST));
 }