Skip to content

Commit

Permalink
update return url to object public url (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
meofiscoding authored Nov 26, 2023
1 parent 29e0b35 commit a825f5d
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public static class GCSHelper
public static string UploadFile(string filePath, string objectName)
{
// set google credential
GoogleCredential credential = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
var storage = StorageClient.Create(credential);
//GoogleCredential credential = GoogleCredential.FromFile(Environment.GetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS"));
var storage = StorageClient.Create();
Stream fileStream;
// check if file path is url
if (filePath.StartsWith("http"))
Expand Down Expand Up @@ -56,8 +56,9 @@ public static string MakePublic(string objectName = "your-object-name")
storageObject.Acl ??= new List<ObjectAccessControl>();
storage.UpdateObject(storageObject, new UpdateObjectOptions { PredefinedAcl = PredefinedObjectAcl.PublicRead });
Console.WriteLine(objectName + " is now public and can be fetched from " + storageObject.SelfLink);

return storageObject.SelfLink;
// get public url
var publicUrl = $"https://storage.googleapis.com/{Consts.BUCKET_NAME}/{objectName}";
return publicUrl;
}

public static bool IsFileExist(string objectName = "your-object-name")
Expand Down

0 comments on commit a825f5d

Please sign in to comment.