cloudinary / cloudinary-go Goto Github PK
View Code? Open in Web Editor NEWCloudinary Golang package
License: MIT License
Cloudinary Golang package
License: MIT License
The principle I was referring to during our conversation is Promoted fields.
You can use a structure name in constructor to define which fields you are defining now:
Here is your structure:
type CreateUploadPresetParams struct {
Name string `json:"name,omitempty"`
Unsigned bool `json:"unsigned,omitempty"`
DisallowPublicId bool `json:"disallow_public_id,omitempty"`
Live bool `json:"live,omitempty"`
uploader.UploadParams
}
And here is instantiation:
updateUPParams := UpdateUploadPresetParams{
Name: UPName,
Unsigned: false,
Live: false,
}
updateUPParams.Tags = api.CldApiArray{"go-tag3", "go-tag4"}
You could change it this way:
updateUPParams := CreateUploadPresetParams{
Name: UPName,
Unsigned: false,
Live: false,
UploadParams: uploader.UploadParams{Tags: api.CldApiArray{"go-tag1", "go-tag2"}},
}
It might be a little overcomplicated but if you'd give a proper name for such a nested struct or split it to several different structs - it should be ok.
package main
import "fmt"
type Size struct {
x int
y int
z int
}
type Box struct {
name string
Size
}
func main() {
box := Box{name: "New box!", Size: Size{x: 100, y: 200, z: 100}}
fmt.Printf("Box x size is %v", box.x)
}
All the errors from SDK now returns in raw format.
Moreover - they are bubbling up from the very bottom level to the client level.
This errors might be everything - starting from the HTTP errors (can't connect to the server, wrong credentials, smth else) to JSON umarshaling problems.
Does the client really need such verbose level of errors and does he (she) really need to know that we've got some problem during JSON unmarshaling?
Before proceeding, please update to the latest version and test if the issue persists
Uploading this 3D model
https://res.cloudinary.com/shirly-dam/image/upload/v1701186432/3d-models/MVILLE_Chill_O_Clock_Singles_Bin.glb
through the SDK results in an error
invalid character '<' looking for beginning of value
but as we can see it is possible to upload it to Cloudinary.
… if applicable
invalid character '<' looking for beginning of value
If possible, please provide a link to a reproducible repository that showcases the problem
Following instructions on adding the Media Upload widget
It recommends using the api.SignParameters
method to generate an upload signature.
Part of this signature is a timestamp - which is generated in the frontend and needs to match the timestamp used to generate the signature.
However the code inside api.SignParameters
will overwrite any existing timestamp given to it.
The result is that sometimes the signature will work (when processed with the same timestamp), and sometimes it won't work (if not processed within the same timestamp period).
This code needs to have a check to ensure that a timestamp doesn't already exist before adding one.
I try to download multiple images as a zip file. When I try the code below I receive the following error: Missing public_ids.
I contacted Cloudinary support and they verified that the golang code used for this library is not correct.
`
var ids = api.CldAPIArray{}
for _, up := range pr.Uploads {
if up.Format == "jpg" {
ids = append(ids, up.PublicID, up.Format)
}
}
url, err := cl.Upload.DownloadZipURL(uploader.CreateArchiveParams{
PublicIds: ids,
ResourceType: api.Image,
})
if err != nil {
logrus.Fatal(err)
}
fmt.Println(url)`
Feature request for Cloudinary Go SDK
…(If your feature is for other SDKs, please request them in the relevant repo)
uploader.UploadParams is missing the optional AccessControl
field that is present in the api documentation Api Link
Since users are unable to use go get until a go mod has been initialized, is it worth including a pre-requisite line before the
go get github.com/cloudinary/cloudinary-go/v2
something like
go mod init cloudinaryexample.com/m/v2
Feature request for Cloudinary Go SDK
When uploading a video file the result contains playback_url
field which is currently not exposed in Cloudinary Go SDK.
Add PlaybackURL
field to UploadResult
Feature request for Cloudinary Go SDK
I need to be able to modify the http.RoundTripper or http.Client to add my own tracing/instrumentation.
Expose a way to modify the http.Client.Transport
via the Configuration that's passed into the client.
If I understand the documentation correctly, a delete request could return partial: true
and a next_cursor
parameter which should be passed to another call to continue the delete operation.
As far as I can tell, the SDK does not return this next_cursor
parameter. I think it should be added to the DeleteAssetsResult
type.
cloudinary.NewFromURL
does not work for custom domains as it returns an instance of cloudinary where further operations return URLs that do not exist.
package main
import (
"context"
"fmt"
"github.com/cloudinary/cloudinary-go"
"log"
)
func main() {
// fake domain and publicId to showcase the issue
cld, err := cloudinary.NewFromURL("https://cms.cloudinary.my-domain.com/image/upload/v1623180876/folder-1/folder-2/my-image.png")
if err != nil {
log.Fatalf("Failed to intialize Cloudinary, %v", err)
}
i, err := cld.Image("folder-1/folder-2/my-image")
i.Transformation = "w_500"
myURL, err := i.String()
fmt.Println(myURL)
}
The above code prints this URL:
https://res.cloudinary.com/cms.cloudinary.my-domain.com/image/upload/w_500/v1/folder-1/folder-2/my-image?_a=AQAK9cJ
which returns 404.
`
func uploadImageToCloudinary(base64str, name string) (*uploader.UploadResult, error) {
cloudinaryURL := os.Getenv("CLOUDINARY_URL")
cloudinaryClient, err := cloudinary.NewFromURL(cloudinaryURL)
if err != nil {
return nil, err
}
formattedString := fmt.Sprintf("data:image/jpeg;base64,%s", base64str)
uploadParams := uploader.UploadParams{
PublicID: name,
UseFilename: true,
UniqueFilename: true,
}
// Upload the Base64 encoded content
result, err := cloudinaryClient.Upload.Upload(context.Background(), formattedString, uploadParams)
if err != nil {
return nil, err
}
return &result, nil
}
`
I tried to do like this and also I tried many but just not working
The Upload API request signing includes all passed parameters to the signing method, despite the documentation clearly states that All parameters added to the method call should be included except: file, cloud_name, resource_type and your api_key.
The server rejects signatures that include one of these values.
This breaks when a ResourceType
field is non-empty in in an UploadParams
struct for a request; it gets marshaled as resource_type
and included in the signature, which doesn't match the server's logic.
See proposed fix #25
…
Enter a ResourceType
field that is non-empty in an UploadParams
struct for a request, e.g. "video".
If possible, please provide a link to a reproducible repository that showcases the problem
I would like to access the context metadata from an asset after calling (*admin.API).Search
.
In my particular use-case, I want to access the alt text of an asset.
The context metadata is not returned as part of a member of the admin.SearchAsset
. The only way of getting the data out with the code as-is is by unmarshaling the SearchResult.Response
field (which is an interface{}
) into a custom data structure, which is error-prone.
The easier way of handling this would be to add a new field called ContextMetadata ContextMetadataResult
which contains the metadata context as a map[string]string
. This is consistent with the current way other pieces of metadata are returned (e.g., ImageMetadata ImageMetadataResult
).
Before proceeding, please update to the latest version and test if the issue persists
func (u *API) UpdateMetadata(ctx context.Context, params RenameParams) (*UpdateMetadataResult, error) {
Takes a RenameParams I would have expected it take type UpdateMetadataParams struct {
Regards
Code search,
… if applicable
cloudinary-go/api/uploader/edit_asset.go
Line 109 in 3a4007e
Before proceeding, please update to the latest version and test if the issue persists
NextCursor
is not sent in the reponse for admin.GetTransformation()
When trying to get the list of derived images from a transform, we do not receive the next_cursor
field in the response, so we can never get more derived images after the first call, even with maxResults: 500
resp, err := cld.Admin.GetTransformation(
context.TODO(),
admin.GetTransformationParams{Transformation: t, MaxResults: 1},
)
if err != nil {
fmt.Println(err)
return nil, err
}
fmt.Printf("%+v\n", resp)
that call results in the following (url names have been removed)
&{Name:t_homepage_carousel_card_image AllowedForStrict:true Used:true Named:true Info:[map[crop:fill gravity:face height:390 width:312] map[radius:10]] Derived:[{PublicID:valid/path/1 ResourceType:image Type:upload Format:jpg URL:http://media.validurl SecureURL:https://media.validurl Bytes:11989 ID:xxx}] Error:{Message:}}
There are more than 500 derived images for this transformation, so we will need to be able to paginate these responses.
Not a bug, just reporting that the current used github.com/gorilla/schema pkg version has a vulnerability, which is solved in version >=1.4.1: https://pkg.go.dev/vuln/GO-2024-2958
Using govulncheck
If possible, please provide a link to a reproducible repository that showcases the problem
I want to call "Explicit" method with moderation request for existing media, but I couldn't get the Moderation property in the response type.
res, err := cld.Upload.Explicit(ctx,
uploader.ExplicitParams{
PublicID: publicId,
Type: "upload",
ResourceType: assetType,
Moderation: moderationMethod})
res.Moderation // not exists
I'd be happy if you'll extend "ExplicitResult" to include that.
Tomer
Before proceeding, please update to the latest version and test if the issue persists
I've looked at the code in this repository and the issue seems to still be there
Analytics doesn't seem to be thread/concurrent safe. I'm not sure if this is deliberate, but seems like it could be an easy fix, since couldn't this initialization happen before the calls to getKey
? https://github.com/cloudinary/cloudinary-go/blob/main/asset/analytics.go#L80
We use cloudinary to get images inside a graphql resolver, which means we use the cloudinary instance across threads. This can result in the stack trace below.
Image
"/go/pkg/mod/github.com/cloudinary/[email protected]/asset/asset.go:93 +0x3d8 fp=0xc0002008c8 sp=0xc0002005f0 pc=0xa522f8"
"github.com/cloudinary/cloudinary-go/asset.Asset.String(0xc7f706, 0x5, 0xc80d02, 0x6, 0xc0002df4f0, 0x9, 0x0, 0xc00013e230, 0x46, 0x0, ...)"
"/go/pkg/mod/github.com/cloudinary/[email protected]/asset/asset.go:287 +0x38 fp=0xc0002005f0 sp=0xc000200588 pc=0xa537f8"
"github.com/cloudinary/cloudinary-go/asset.(*Asset).query(0xc0002008c8, 0x6, 0x6)"
"/go/pkg/mod/github.com/cloudinary/[email protected]/asset/analytics.go:29 +0x62 fp=0xc000200588 sp=0xc0002004d8 pc=0xa511a2"
"github.com/cloudinary/cloudinary-go/asset.sdkAnalyticsSignature(0x82, 0x8)"
"/go/pkg/mod/github.com/cloudinary/[email protected]/asset/analytics.go:71 +0x3dd fp=0xc0002004d8 sp=0xc000200408 pc=0xa517fd"
"github.com/cloudinary/cloudinary-go/asset.encodeVersion(0xc7f0ad, 0x5, 0x82, 0x3, 0x4, 0x40)"
"/go/pkg/mod/github.com/cloudinary/[email protected]/asset/analytics.go:80 +0x190 fp=0xc000200408 sp=0xc000200360 pc=0xa51ae0"
"github.com/cloudinary/cloudinary-go/asset.getKey(0xc00013adc0, 0x6, 0x3, 0xc0002ecc30)"
"/usr/local/go/src/runtime/map_faststr.go:291 +0x3fe fp=0xc000200360 sp=0xc0002002f8 pc=0x412e9e"
"runtime.mapassign_faststr(0xb7b5a0, 0xc0000f91a0, 0xc0002df580, 0x6, 0x2)"
"/usr/local/go/src/runtime/panic.go:774 +0x72 fp=0xc0002002f8 sp=0xc0002002c8 pc=0x42dc02"
"runtime.throw(0xc8bb2b, 0x15)"
"goroutine 26 [running]:"
"fatal error: concurrent map writes"
If possible, please provide a link to a reproducible repository that showcases the problem
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.