This module declares a common interface for physically agnostic storage backends. Whatever a way to implement a storage, it needs only common operations of the interface. This consists of some basic operations like writing, reading, deletion, and finding urls.
Modules that implement the storage interface inside sqlalchemy_imageattach.storages package might help to implement a new storage backend.
The interface of image storage backends. Every image storage backend implementation has to implement this.
Delete the file of the given image.
Parameters: | image (sqlalchemy_imageattach.entity.Image) – the image to delete |
---|
Deletes all reproducible files related to the image. It doesn’t raise any exception even if there’s no such file.
Parameters: |
|
---|
Gets the file-like object of the given criteria.
Parameters: |
|
---|---|
Returns: | the file of the image |
Return type: | file-like object, file |
Raises exceptions.IOError: | |
when such file doesn’t exist |
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers should use open() method instead of this.
Gets the file-like object of the given criteria.
Parameters: |
|
---|---|
Returns: | the url locating the image |
Return type: | basestring |
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers should use locate() method instead of this.
Gets the URL of the given image.
Parameters: | image (sqlalchemy_imageattach.entity.Image) – the image to get its url |
---|---|
Returns: | the url of the image |
Return type: | basestring |
Opens the file-like object of the given image. Returned file-like object guarantees:
To sum up: you definitely can read the file, in with statement and for loop.
Plus, if use_seek option is True:
For example, if you want to make a local copy of the image:
import shutil
with store.open(image) as src:
with open(filename, 'wb') as dst:
shutil.copyfileobj(src, dst)
Parameters: |
|
---|---|
Returns: | the file-like object of the image, which is a context manager (plus, also seekable only if use_seek is True) |
Return type: | file, FileProxy, file-like object |
Raises exceptions.IOError: | |
when such file doesn’t exist |
Puts the file of the image.
Parameters: |
|
---|
Note
This is an abstract method which has to be implemented (overridden) by subclasses.
It’s not for consumers but implementations, so consumers should use store() method instead of this.
Stores the actual data file of the given image.
with open(imagefile, 'rb') as f:
store.store(image, f)
Parameters: |
|
---|