Ejemplo n.º 1
0
        public async Task <AppFile> UploadFileAsync(HttpPostedFile file)
        {
            try
            {
                Stream         streamFile          = file.InputStream;
                RegionEndpoint bucketRegion        = RegionEndpoint.GetBySystemName(regionName);
                IAmazonS3      s3Client            = new AmazonS3Client(key, secretKey, bucketRegion);
                var            fileTransferUtility = new TransferUtility(s3Client);

                Guid guid = Guid.NewGuid();

                TransferUtilityUploadRequest request = new TransferUtilityUploadRequest();
                request.BucketName  = bucketName;
                request.Key         = string.Format(filePath, guid, file.FileName);
                request.InputStream = streamFile;

                await fileTransferUtility.UploadAsync(request);

                int     id          = Insert("/" + request.Key, file.FileName);
                AppFile responseObj = new AppFile();
                responseObj.Id   = id;
                responseObj.Path = Convert.ToString(_keysService.GetByKeyName <string>("AWS.PathLink")) + "/" + request.Key;
                return(responseObj);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
                return(null);
            }
        }
Ejemplo n.º 2
0
 public SmsService(IDataProvider dataProvider, IKeysService keysService)
 {
     _keysService      = keysService;
     _dataProvider     = dataProvider;
     accountsid        = Convert.ToString(_keysService.GetByKeyName <string>("Account.Sid"));
     authtoken         = Convert.ToString(_keysService.GetByKeyName <string>("AuthToken"));
     serverPhoneNumber = Convert.ToString(_keysService.GetByKeyName <string>("ServerPhoneNumber"));
 }
Ejemplo n.º 3
0
 public FilesService(IDataProvider dataProvider, IKeysService keysService)
 {
     _keysService  = keysService;
     key           = Convert.ToString(_keysService.GetByKeyName <string>("AWS.KeyId"));
     secretKey     = Convert.ToString(_keysService.GetByKeyName <string>("AWS.AccessSecret"));
     bucketName    = Convert.ToString(_keysService.GetByKeyName <string>("Bucket"));
     filePath      = Convert.ToString(_keysService.GetByKeyName <string>("Aws.FilePath"));
     regionName    = Convert.ToString(_keysService.GetByKeyName <string>("Aws.RegionName"));
     _dataProvider = dataProvider;
 }
Ejemplo n.º 4
0
        public HttpResponseMessage GetStrByName(string keyname)
        {
            object result = _service.GetByKeyName <Key <object> >(keyname);
            ItemResponse <Key <object> > responseBody = new ItemResponse <Key <object> >();
            Key <object> key = result as Key <object>;

            responseBody.Item = key;
            HttpStatusCode statusCode = HttpStatusCode.OK;

            if (responseBody.Item == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            if (responseBody.Item.IsSecured == true)
            {
                return(Request.CreateResponse(HttpStatusCode.Forbidden));
            }
            if (responseBody.Item == null)
            {
                statusCode = HttpStatusCode.NotFound;
            }
            return(Request.CreateResponse(statusCode, responseBody));
        }