public GxExternalFileInfo(string storageObjectFullname, string url, ExternalProvider provider, GxFileType fileType = GxFileType.Public) { _name = storageObjectFullname; _provider = provider; _url = url; _fileTypeAtt = fileType; }
public GxExternalFileInfo(string storageObjectFullname, ExternalProvider provider, GxFileType fileType) { storageObjectFullname = storageObjectFullname != null?storageObjectFullname.Replace('\\', '/') : storageObjectFullname; _name = storageObjectFullname; _provider = provider; Uri result; if (Uri.TryCreate(storageObjectFullname, UriKind.Absolute, out result) && result.IsAbsoluteUri) { _url = storageObjectFullname; } else { if (fileType.HasFlag(GxFileType.Attribute)) //Attributes multimedia consider Storage Provider Folder { _url = provider.GetBaseURL() + storageObjectFullname; _name = _url.Replace(provider.StorageUri, string.Empty); if (_name.StartsWith("/")) { _name = _name.Substring(1, _name.Length - 1); } } } _fileTypeAtt = fileType; }
public void Download(string externalFileName, string localFile, GxFileType fileType) { string localDirectory = Path.GetDirectoryName(localFile); string localFileName = Path.GetFileName(localFile); openstackFilesProvider.GetObjectSaveToFile(GetBucket(fileType), localDirectory, externalFileName, localFileName); }
public long GetLength(string objectName, GxFileType fileType) { CloudBlockBlob blob = GetCloudBlockBlob(objectName, fileType); blob.FetchAttributesAsync().GetAwaiter().GetResult(); return(blob.Properties.Length); }
public void Download(string objectName, string localFile, GxFileType fileType) { using (var fileStream = new System.IO.FileStream(localFile, FileMode.Create)) { Client.DownloadObject(Bucket, objectName, fileStream); } }
public void Delete(string objectName, GxFileType fileType) { Google.Apis.Storage.v1.Data.Object obj = new Google.Apis.Storage.v1.Data.Object(); obj.Name = objectName; obj.Bucket = Bucket; Client.DeleteObject(obj); }
public Stream GetStream(string objectName, GxFileType fileType) { var stream = new MemoryStream(); Client.DownloadObject(Bucket, objectName, stream); return(stream); }
public string Rename(string objectName, string newName, GxFileType fileType) { string ret = Copy(objectName, fileType, newName, fileType); Delete(objectName, fileType); return(ret); }
public Stream GetStream(string objectName, GxFileType fileType) { using (Stream stream = new MemoryStream()) { openstackFilesProvider.GetObject(GetBucket(fileType), objectName, stream); return(stream); } }
public Stream GetStream(string objectName, GxFileType destFileType) { GetObjectResponse getObjRespone = GetObject(Bucket, objectName); MemoryStream stream = new MemoryStream(); getObjRespone.ResponseStream.CopyTo(stream); return(stream); }
public Stream GetStream(string objectName, GxFileType fileType) { CloudBlockBlob blob = GetCloudBlockBlob(objectName, fileType); Stream stream = new MemoryStream(); blob.DownloadToStreamAsync(stream).GetAwaiter().GetResult(); return(stream); }
private string GetBucket(GxFileType fileType) { if (fileType.HasFlag(GxFileType.Private)) { return(privateBucketName); } return(publicBucketName); }
public string Upload(string localFile, string objectName, GxFileType fileType) { using (FileStream stream = new FileStream(localFile, FileMode.Open)) { Google.Apis.Storage.v1.Data.Object obj = Client.UploadObject(Bucket, objectName, "application/octet-stream", stream, GetUploadOptions(fileType)); return(obj.MediaLink); } }
public string Copy(string objectName, GxFileType sourceFileType, string newName, GxFileType destFileType) { CloudBlockBlob sourceBlob = GetCloudBlockBlob(objectName, sourceFileType); CloudBlockBlob targetBlob = GetCloudBlockBlob(newName, destFileType); targetBlob.StartCopyAsync(sourceBlob).GetAwaiter().GetResult(); return(GetURL(targetBlob, destFileType)); }
public string Get(string objectName, GxFileType fileType, int urlMinutes) { if (Exists(objectName, fileType)) { return(GetURL(objectName, fileType, urlMinutes)); } return(string.Empty); }
public void Delete(string objectName, GxFileType fileType) { DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest { BucketName = Bucket, Key = objectName }; DeleteObject(deleteObjectRequest); }
public string Get(string objectName, GxFileType fileType, int urlMinutes) { CloudBlockBlob blob = GetCloudBlockBlob(objectName, fileType); if (blob.ExistsAsync().GetAwaiter().GetResult()) { return(GetURL(blob, fileType, urlMinutes)); } return(string.Empty); }
public long GetLength(string objectName, GxFileType fileType) { foreach (ContainerObject obj in openstackFilesProvider.ListObjects(GetBucket(fileType))) { if (obj.Name.Equals(objectName)) { return(obj.Bytes); } } return(0); }
private string GetURL(string objectName, GxFileType fileType, int urlMinutes = 60 * 24 * 7) { if (fileType.HasFlag(GxFileType.Private)) { return(Signer.Sign(Bucket, StorageUtils.EncodeUrl(objectName), TimeSpan.FromMinutes(urlMinutes), HttpMethod.Get)); } else { return(StorageUri + StorageUtils.EncodeUrl(objectName)); } }
public DateTime GetLastModified(string objectName, GxFileType fileType) { foreach (ContainerObject obj in openstackFilesProvider.ListObjects(GetBucket(fileType))) { if (obj.Name.Equals(objectName)) { return(obj.LastModified.UtcDateTime); } } return(new DateTime()); }
public bool Exists(string objectName, GxFileType fileType) { try { openstackFilesProvider.GetObjectMetaData(GetBucket(fileType), objectName); return(true); } catch (ItemNotFoundException) { return(false); } }
public void Download(string objectName, string localFile, GxFileType fileType) { GetObjectRequest request = new GetObjectRequest { BucketName = Bucket, Key = objectName, }; GetObjectResponse response = GetObject(request); WriteResponseStreamToFile(response, localFile); }
public GxFile(string baseDirectory, string fileName, GxFileType fileType = GxFileType.Public) : this(baseDirectory) { fileName = fileName.Trim(); if ((GXServices.Instance != null && GXServices.Instance.Get(GXServices.STORAGE_SERVICE) != null) && !Path.IsPathRooted(fileName)) { _file = new GxExternalFileInfo(fileName, ServiceFactory.GetExternalProvider(), fileType); } else { _file = new GxFileInfo(fileName, baseDirectory); } }
public string Upload(string localFile, string objectName, GxFileType fileType) { PutObjectRequest objectRequest = new PutObjectRequest() { BucketName = Bucket, Key = objectName, FilePath = localFile, CannedACL = GetCannedACL(fileType) }; PutObjectResponse result = PutObject(objectRequest); return(Get(objectName, fileType)); }
private string GetURL(CloudBlockBlob blob, GxFileType fileType, int urlMinutes = 0) { string url = StorageUri + StorageUtils.DELIMITER + blob.Container.Name + StorageUtils.DELIMITER + StorageUtils.EncodeUrl(blob.Name); if (IsPrivateFile(fileType)) { SharedAccessBlobPolicy sasConstraints = new SharedAccessBlobPolicy(); sasConstraints.SharedAccessStartTime = DateTime.UtcNow; sasConstraints.SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes((urlMinutes > 0) ? urlMinutes : 60 * 24 * 7); sasConstraints.Permissions = SharedAccessBlobPermissions.Read; url += blob.GetSharedAccessSignature(sasConstraints); } return(url); }
private static UploadObjectOptions GetUploadOptions(GxFileType fileType) { UploadObjectOptions options = new UploadObjectOptions(); if (fileType.HasFlag(GxFileType.Private)) { options.PredefinedAcl = PredefinedObjectAcl.ProjectPrivate; } else { options.PredefinedAcl = PredefinedObjectAcl.PublicRead; } return(options); }
//https://github.com/aws/aws-sdk-net/blob/master/sdk/src/Services/S3/Custom/_bcl/IO/S3FileInfo.cs public bool Exists(string objectName, GxFileType fileType) { bool exists = true; try { exists = new S3FileInfo(Client, Bucket, objectName).Exists; } catch (Exception) { exists = false; } return(exists); }
public string Copy(string objectName, GxFileType sourceFileType, string newName, GxFileType destFileType) { CopyObjectRequest request = new CopyObjectRequest { SourceBucket = Bucket, SourceKey = objectName, DestinationBucket = Bucket, DestinationKey = newName, CannedACL = GetCannedACL(destFileType) }; CopyObject(request); return(StorageUri + StorageUtils.EncodeUrl(newName)); }
private static CopyObjectOptions GetCopyOptions(GxFileType fileType) { CopyObjectOptions options = new CopyObjectOptions(); if (fileType.HasFlag(GxFileType.Private)) { options.DestinationPredefinedAcl = PredefinedObjectAcl.ProjectPrivate; } else { options.DestinationPredefinedAcl = PredefinedObjectAcl.PublicRead; } return(options); }
private CloudBlockBlob GetCloudBlockBlob(string externalFileName, GxFileType fileType) { CloudBlockBlob blob; if (fileType.HasFlag(GxFileType.Private)) { blob = PrivateContainer.GetBlockBlobReference(externalFileName); } else { blob = PublicContainer.GetBlockBlobReference(externalFileName); } return(blob); }