uploaded images not getting displayed on google cloud storage using c# but pdf file is ok -
i writing code in c# upload images on google clould storage type of files uploaded successfully, , pdf files brow-sable also, when uploading images seems corrupt file. idea happened use 2 types of code no lock.
public string uploadmedia(string folderno, string filename, stream _media) { var credential = googlecredential.fromstream(new filestream(@"\\files\shared\application_default_credentials.json", filemode.open)).createscoped(new string[] { storageservice.scope.devstoragereadwrite }); var client = storageclient.create(credential); var bucketname = "******"; var obj1 = client.uploadobjectasync(bucketname, folderno + "/" + filename, "image/jpg", _media); return obj1.result.name; }
also used below code image uploading not working @ all
public string uploadmedia(string folderno, string filename, stream _media) { try { string serviceaccountemail = "ddds-storage@hhs-svm2.iam.gserviceaccount.com"; var certificate = new x509certificate2(@"\\files\shared\hhhx-4d75037a35bf.p12", "notasecret", x509keystorageflags.exportable); serviceaccountcredential credential = new serviceaccountcredential( new serviceaccountcredential.initializer(serviceaccountemail) { scopes = new[] { google.apis.storage.v1.storageservice.scope.devstoragefullcontrol } }.fromcertificate(certificate)); google.apis.storage.v1.storageservice ss = new google.apis.storage.v1.storageservice(new google.apis.services.baseclientservice.initializer() { httpclientinitializer = credential, applicationname = "hhs_svm2", }); var fileobj = new google.apis.storage.v1.data.object() { bucket = "hhhs", name = filename, contenttype = "image/png" }; byte[] rf = readfully(_media); google.apis.storage.v1.objectsresource.insertmediaupload insmedia; insmedia = new google.apis.storage.v1.objectsresource.insertmediaupload(ss, fileobj, "tamkeen_svm", new memorystream(rf), "image/png"); insmedia.upload(); }
Comments
Post a Comment