Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base64file uploading to cloudinary is not working #82

Open
bete7512 opened this issue Aug 11, 2023 · 2 comments
Open

Base64file uploading to cloudinary is not working #82

bete7512 opened this issue Aug 11, 2023 · 2 comments

Comments

@bete7512
Copy link

bete7512 commented Aug 11, 2023

`

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

@skalahasti-cloudinary
Copy link

Hi @bete7512 ,

Thanks for contacting Cloudinary.

I used the below code to upload and it worked fine. Can you please let us know what error are you facing?

func credentials() (*cloudinary.Cloudinary, context.Context) {
// Add your Cloudinary credentials, set configuration parameter
// Secure=true to return "https" URLs, and create a context
//===================
cld, _ := cloudinary.NewFromParams("", "", "")
cld.Config.URL.Secure = true
ctx := context.Background()
return cld, ctx
}

func uploadBase64Image(cld *cloudinary.Cloudinary, ctx context.Context) {
resp, err :=
cld.Upload.Upload(ctx, "data:image/png;base64,",
uploader.UploadParams{})
if err != nil {
fmt.Println("error")
}
// Log the delivery URL
fmt.Println("2. Upload an image\nDelivery URL:", resp.SecureURL)
}

Thanks,
Sree

@AnshShah77
Copy link

Can u please assign this to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants