Delete attachment in django - django

I have some points with unique identifiers. Each point has a file attached to it. How do I delete files at a specific point?
https://github.com/testdrivenio/django-ajax-xhr/blob/jquery/static/main.js#L19-L41

Related

Google Cloud Storage JSON REST API - Insert and List objects in a sub-directory in a bucket

I'm trying to figure out how to:
a) Store / insert an object on Google Cloud Storage within a sub-directory
b) List a given sub-directory's contents
I managed to resolve how to get an object here: Google Cloud Storage JSON REST API - Get object held in a sub-directory
However, the same logic doesn't seem to apply to these other types of call.
For store, this works:
https://www.googleapis.com/upload/storage/v1/b/bucket-name/o?uploadType=media&name=foldername%2objectname
but it then stores the file name on GCS as foldername_filename, which doesn't change functionality but isn't really ideal.
For listing objects in a bucket, not sure where the syntax for a nested directory should go in here: storage.googleapis.com/storage/v1/b/bucketname/o.
Any insight much appreciated.
The first thing to know is that GCS does not have directories or folders. It just has objects that share a fixed prefix. There are features that both gsutil and the UI used to create the illusion that folders do exist.
https://cloud.google.com/storage/docs/gsutil/addlhelp/HowSubdirectoriesWork
With that out of the way: to create an object with a prefix you need to URL encode the object name, as I recall %2F is the encoding for /:
https://cloud.google.com/storage/docs/request-endpoints#encoding
Finally to list only the objects with a common prefix you would use the prefix parameter:
https://cloud.google.com/storage/docs/json_api/v1/objects/list#parameters
Using prefix=foo/bar/baz (after encoding) would list all the objects in the foo/bar/baz "folder", note that this is recursive, it will include foo/bar/baz/quux/object-name in the results. To stop at one level you want to read about the delimiter parameter too.

OpenCart 2.3.0.2 - Where did my bad extension go?

I am experimenting to make a new extension in my OpenCart 2.3.02, and I did a mistake in the code.
Now my admin panel will not load at all, just a white page - and I cant remove the extension the normal way.
The file must be somewhere on the server, but I can't find it. Could anyone tell me where they go?
Remember , backup first
Go to system/storage/modification and delete all files and folder, it will load your site temporarily until you clear and rebuild cache from extension install / modification.
1.Go to admin/controller/extension/module and delete your created extension file.
2.Go to admin/language/en-gb/extension/module and delete your created extension file.
3.Go to admin/view/template/extension/module and delete your created extension file.
4.Go to catalog/controller/extension/module and delete your created extension file.
5.Go to catalog/language/en-gb/extension/moduleand delete your created extension file.
6.Go to catalog/view/template/extension/module and delete your created extension file.
i think its helpful for you to fix error...

If I change ImageFIeld.upload_to parameter, should it move previously uploaded files upon migration?

I have a Django model with
...
image = models.ImageField(default=None, upload_to=settings.PHOTO_UPLOAD_TO)
...
I have changed the value of settings.PHOTO_UPLOAD_TO, but the files have remained where they were, and the database entries also don't seem to have changed. A newly added image is placed in the correct new location, but not the old ones. Is it an expected behaviour? Is there a way to migrate the image locations? I would like to slightly change the directory/URL structure of my project.
The path of a FileField/ImageField is stored relative to MEDIA_ROOT, so if you want to move the files to the new upload_to folder, you're gonna need to put that in your migration yourself (like you suggested).

Upload files to dynamic folders using random string in models.Filefield 'upload_to' entry

I am using models.Filefield to upload files to the server. When uploading a new file with name of an existing file, django append name with some random characters. But I need to retain filename. Hence I change upload_to entry in the models.Filefield to upload_to='str(uuid.uuid4())'. It works fine, but seldom the above problem occur. Is there any other methods to correct it ?

Can someone explain AWS GET?

For reference: GET Bucket (List Objects)
When I do a get request on the root bucket it comes back with test/ and test/subdir/ both 0 bytes. Which is correct, there should be 2 folders up there. When I upload a file to test/subdir/file. The root bucket has an item with the key=test/subdir/file. test/ and test/subdir/ are still 0 bytes. When I do a get request on test/subdir/ it returns nothing.
What's going on here?
Note: I do not have access to the console.
Greg, this might sound confusing at first, but the truth is that there's no such thing as "a folder" in Amazon S3. I'll explain.
The data structure of S3 is like a flat list of objects -- not like a tree. When you think you have a "file" called puppy.jpg inside a "folder" called pics, what you actually have is an object which key is pics/puppy.jpg. Note that the / character is not any more special than the . character, or the p characters.
You might be thinking, Bruno is nuts, I see folders in the AWS Management Console. True, you see the folders. But they are actually emulated by the GUI.
When you create a folder through the AWS Management Console, what it will actually do is create an object which name is the full path of the "folder", with a trailing slash, and 0 bytes. Just like the test/ object (not "folder") and the test/subdir/ object (not "folder") you mention in your question.
To actually identify and draw "folders", the AWS Management Console (as well as many other S3 browsing tools) is doing is some API magic with the parameters delimiter and prefix.
Now, knowing the fact that there's no such thing as a folder, and that they are emulated through the use of those 0-byte, trailing-/ objects, it should be easy to understand why you see the test/ object as a 0-byte object... The same reasoning would explain why you see nothing when you do a GET on a "folder" -- you are actually downloading a 0-byte object!
Finally, as a conclusion, there's no easy way to obtain from S3 the size of "a folder" (they don't exist...). The only way would be for you to list all the objects with that prefix and add their sizes. Or keep an index of your object ("files" and "folders") in some kind of database with more advanced querying capabilities.