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

[QUESTION] Delete method #162

Open
JonatanAlcaraz opened this issue Nov 22, 2023 · 3 comments
Open

[QUESTION] Delete method #162

JonatanAlcaraz opened this issue Nov 22, 2023 · 3 comments

Comments

@JonatanAlcaraz
Copy link

Is there any method to delete objects from a bucket by key without deleting the whole bucket?

Thanks

@egonelbre
Copy link
Member

Yes, there's DeleteObject https://pkg.go.dev/storj.io/uplink#Project.DeleteObject.

@JonatanAlcaraz
Copy link
Author

Thanks for your reply @egonelbre

I was trying to integrate it but the result I get is always a null object but at the same time it does not return error. The steps I follow are the following:

        access, err := uplink.ParseAccess(s.AccessGrant)
	if err != nil {
		fmt.Println(err)
	}
        if err != nil {
		return fmt.Errorf("could not generate access: %v", err)
	}
	project, err := uplink.OpenProject(ctx, access)
	if err != nil {
		return fmt.Errorf("could not open project: %v", err)
	}
	// here I try to execute the method with the object name
        deleted, err := project.DeleteObject(ctx, s.BucketName, objectKey)
        
        // here I try to execute the method with the path of the object 
	key := fmt.Sprintf("%s%s", s.ObjectPath, objectKey)
	deleted, err := project.DeleteObject(ctx, s.BucketName, key)

Just in case after the process I checked if the file is still inside the bucket and it remains in the bucket.
In addition, when generating the "access garant"in the storj dashboard, I set the Read, Write, List and Delete permissions.

@egonelbre
Copy link
Member

Yeah, DeleteObject is somewhat weird in that sense that it doesn't return an error when the object doesn't exist.

But, a common bug is to use the wrong object key, e.g. accidentally using /image.jpg instead of image.jpg. You can use ListObjects to print out things in the bucket and see what you get.

Another common bug is to use different passphrases in your code and dashboard -- in which case the encrypted object keys won't match.

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

2 participants