Lurk / cloudinary_rs

unofficial cloudinary rust SDK
4 stars 6 forks source link

Update result.rs original_filename #1

Closed Daudongit closed 1 year ago

Daudongit commented 1 year ago

Change original_filename in result to original_extension (the field has been updated from the response)

Lurk commented 1 year ago

You are serious? Who does that without changing documentation?

Lurk commented 1 year ago

@Daudongit Ok. I just tested it. They do not replace original_filename with original_extension, they added original_extension field and forget to update documentation.

Can you update the PR?

Daudongit commented 1 year ago

@Lurk Ok, sure I will update the PR

Daudongit commented 1 year ago

@Lurk so, after adding the two fields(original_filename and original_extension) I get the following error during testing

err = Anyhow(
        Error { 
            context: "failed to parse:\n\n {\"asset_id\":\"55a257c85685b7438082b3eb570f0e17\",\"public_id\":\"nominee_91388.jpg\",\"version\":1683488309,\"version_id\":\"455ff22673e8960d796ff94a10254d80\",\"signature\":\"4c72584efd76e8c8cddf4fcec1ff4fade7e63edd\",\"width\":310,\"height\":360,\"format\":\"jpg\",\"resource_type\":\"image\",\"created_at\":\"2023-05-07T19:38:29Z\",\"tags\":[],\"bytes\":24338,\"type\":\"upload\",\"etag\":\"e085f576c7145677573b8c223636fd4d\",\"placeholder\":false,\"url\":\"http://res.cloudinary.com/dolnl2kjz/image/upload/v1683488309/nominee_91388.jpg.jpg\",\"secure_url\":\"https://res.cloudinary.com/dolnl2kjz/image/upload/v1683488309/nominee_91388.jpg.jpg\",\"folder\":\"\",\"original_extension\":\"tmpeyncFw\",\"api_key\":\"********\"}",                                                                       
            source: Error("data did not match any variant of untagged enum UploadResult", line: 0, column: 0),                                                                  },                                                                                                                                                                  
  )

For more clarity here is the return json sample

{
  "asset_id": "55a257c85685b7438082b3eb570f0e17",
  "public_id": "nominee_91388.jpg",
  "version": 1683488309,
  "version_id": "455ff22673e8960d796ff94a10254d80",
  "signature": "4c72584efd76e8c8cddf4fcec1ff4fade7e63edd",
  "width": 310,
  "height": 360,
  "format": "jpg",
  "resource_type": "image",
  "created_at": "2023-05-07T19:38:29Z",
  "tags": [],
  "bytes": 24338,
  "type": "upload",
  "etag": "e085f576c7145677573b8c223636fd4d",
  "placeholder": false,
  "url": "http://res.cloudinary.com/dolnl2kjz/image/upload/v1683488309/nominee_91388.jpg.jpg",
  "secure_url": "https://res.cloudinary.com/dolnl2kjz/image/upload/v1683488309/nominee_91388.jpg.jpg",
  "folder": "",
  "original_extension": "tmpeyncFw",
  "api_key": "********"
}

I was only able to get it to work by removing the original_filename field. Is there something I'm missing ?

Lurk commented 1 year ago

@Daudongit, that looks off.

"url": "http://res.cloudinary.com/dolnl2kjz/image/upload/v1683488309/nominee_91388.jpg.jpg",

.jpg.jpg - this part looks wrong.

Try to set the public id

async fn upload_test() -> Result<UploadResult> {
    let cloudinary = Cloudinary::new(
        dotenv::var("api_key").unwrap(),
        dotenv::var("cloud_name").unwrap(),
        dotenv::var("api_secret").unwrap(),
    );
    let options = UploadOptions::new().set_public_id("test".to_string());

    cloudinary
        .upload_image("./data/1.jpeg".to_string(), &options)
        .await
}

produces

{
   "asset_id":"ddfb49e6cf5ac45ecba193a071a09cc",
   "public_id":"test",
   "version":1685434378,
   "version_id":"1a16f4a76aec570ce879b733545270",
   "signature":"669a5ca6a61540954dc00a5966529db10a0a53",
   "width":768,
   "height":1024,
   "format":"jpg",
   "resource_type":"image",
   "created_at":"2023-05-30T08:12:58Z",
   "tags":[],
   "bytes":219871,
   "type":"upload",
   "etag":"f87ffc895cb68a63fea55cabf6535",
   "placeholder":false,
   "url":"http://res.cloudinary.com/barhamon/image/upload/v1685434378/test.jpg",
   "secure_url":"https://res.cloudinary.com/barhamon/image/upload/v1685434378/test.jpg",
   "folder":"",
   "original_filename":"1",
   "original_extension":"jpeg",
   "api_key":"25587333815"
}

And if I upload an image with .jpg extension it gives back

{
   "asset_id":"ddfb49e6cf5ecba193a071a09ccd",
   "public_id":"test",
   "version":1685434378,
   "version_id":"1a16f4a76aec57733545270e",
   "signature":"669a5ca6a4dc00a5966529db10a0a53",
   "width":768,
   "height":1024,
   "format":"jpg",
   "resource_type":"image",
   "created_at":"2023-05-30T08:12:58Z",
   "tags":[],
   "bytes":219871,
   "type":"upload",
   "etag":"f87ffc895cb68aabf6535",
   "placeholder":false,
   "url":"http://res.cloudinary.com/barhamon/image/upload/v1685434378/test.jpg",
   "secure_url":"https://res.cloudinary.com/barhamon/image/upload/v1685434378/test.jpg",
   "folder":"",
   "overwritten":true,
   "original_filename":"1",
   "api_key":"255868333815"
}

with no original_extension field.

which means two things:

  1. both of them (original_filename, original_extension) should be optional
  2. set_public_id should be mandatory (?)
Daudongit commented 1 year ago

@Lurk I have updated the PR by making both original_filename and original_extension optional

Lurk commented 1 year ago

@Daudongit Thank you for the contribution!

Daudongit commented 1 year ago

@Lurk sorry but I have to ask why don't you publish it on create.io

Lurk commented 1 year ago

@Daudongit have not thought that someone needs this as a package. By this I mean half backed state of the project.

But now I can see that it is not the case and maybe I should put some effort into it and release.

Lurk commented 1 year ago

@Daudongit Here you go https://crates.io/crates/cloudinary