I have been trying to upload files to backblaze through API using python. The following is the code snippet I used. Import json import urllib2 import hashlib uploadurl = ' # Provided by b2getuploadurl uploadauthorizationtoken = ' # Provided by b2getuploadurl filedata = 'Now, I am become Death, the destroyer of worlds.' I have been trying to upload files to backblaze through API using python. The following is the code snippet I used. Import json import urllib2 import hashlib uploadurl = ' # Provided by b2getuploadurl uploadauthorizationtoken = ' # Provided by b2getuploadurl filedata = 'Now, I am become Death, the destroyer of worlds.'
django backblaze b2 storage using b2sdk (can be used outside of django for upload/download single files too)
Install
Backup a github repository from Windows. Assumes B2 command lines tools, python, and 7ZIP are installed. Script requires some variables (B2 account, etc) to filled in. BackupGHRepoToBackblaze.bat.
Install the last stable release
Create bucket at backblaze.com. No need for older versions of saved files:While royendgel/django-backblazeb2-storage uses older versions, django-b2 will always rename to unique filename.
Add this to Django settings
Of course B2_. values (.KEY.) should never be published.Don't upload the settings file to public sites (github, .) or use some technique to hide the secret parameters.This can be environment variables or hidden config file. Drivers mge ups. You can see tests/test_B2Storage.py for ideas.
Upload library which enforces name uniqueness
django_b2 saves each file into unique folder ie. as /name.This should prevent problems with non unique names.If this doesn't work properly in your case especially if other tool makes the same thing you should turn this feature off.Example: django_drf_filepond creates similar uniquely named folders. In such case set
Drivers initio others. We recommend set this always (False|True) because the default could change in the future.
Imagekit which need reopen the picture soon (Wagtail?), local filesystem cache
If you upload an image and the imagekit want to reopen it immediately (to create thumbnails or so) it can failbecause backblaze storage has the file not immediately accessible.We handle this that way that you can add B2_LOCAL_MEDIA into your settings.
M means that the copy of file is saved to the local filesystem MEDIA_ROOT too and the file is opened from this local 'cache'.That way the files are soon and faster accessible.L means that a log files are written into <MEDIA_ROOT>/_log.With help of logs (files in _log directory) the locally cached files can be deleted: one hour later or 5 days later.
Manycam driver download. There is a script (django management command) b2_clear_local_media usable via cron, celery,.It will delete local media files older than few hours or days. Later they will be served from backblaze.
Using outside of Django
Don't use the storage.py file. Use the backblaze_b2.py only.
Large uploads
Nginx large file uploads:You need at least modify /etc/nginx/nginx.conf, http section, add client_.. settings.
Read: https://vsoch.github.io/2018/django-nginx-upload/
Example:
Upload (backup) single file (new in 0.2.0)
This is implemented in backblaze_b2.py file if called as script.We don't implement it (yet) as the django management command. That means outside of Django: You can use this too.And in Django: No need (at 0.2.0) to add this package to INSTALLED_APPS.
You can describe the target bucket in environment variables or in the .ini file. For details:
Backup the postgres database (new in 0.2.0)
Once django-b2 is installed, pgtob2.sh script is available in the virtual environment.Write 'which pgtob2.sh' for its location.See comments inside the script for more info.
More (this is not well tested)
django-tenants instead of django-tenant-schemas? Maybe it could work but the mixin is inside the django-tenant-schemas package.Add django-tenant-schemas into requirements too but don't add it into INSTALLED_APPS/SHARED_APPS.
storage=B2Storage() in models, turn it off during tests. See https://github.com/pyutil/django-b2/issues/4To work as real B2Storage, 'B2Storage' string must be contained in settings.DEFAULT_FILE_STORAGE.Otherwise DEFAULT_FILE_STORAGE will be instantiated.This makes following in tests possible:@override_settings(DEFAULT_FILE_STORAGE='django.core.files.storage.FileSystemStorage')
Developers
Upload and Download methods work, but probably very stupid and non-effective.If you understand the problem more, please help rewrite them and send pull request:
- fork pyutil/django-b2,
- clone your fork,
- set upstream in git config to pyutil/,
- arrange virtual environment and install (pip install -r ..) requirements.txt & requirements_dev.txt,
- don't touch 'master' branch so you can always pull pyutil/ upstream,
- create a 'fork' branch where you can always merge 'master' and feature branches,
- create a ' branch(es) for every single change,
- commit+push ' branch,
- in github web interface generate a pull request,
- merge ' branch into 'fork' branch (optional)(maybe you have better idea how to arrange branches in your fork)
Tests
Backblaze B2 Python Free
Install test requirements inside your virtual environment
Create a backblaze bucket.Set B2_. environment variables or a config file /etc/django/test-django-b2/env.ini - see tests/test_B2Storage.py.Run pytest.Alternatively you can run tox:You could install pyenv system-wide, pyenv install required 3.N python versions (see tox.ini).Then in the project dir: pyenv local 3.x.x 3.y.y 3.z.zAnd run: tox
Package Details: backblaze-b2 2.3.0-3
Package Actions
- View PKGBUILD / View Changes
Git Clone URL: | https://aur.archlinux.org/backblaze-b2.git (read-only, click to copy) |
---|---|
Package Base: | backblaze-b2 |
Description: | Backblaze B2 Command Line Client |
Upstream URL: | https://github.com/Backblaze/B2_Command_Line_Tool |
Keywords: | |
Licenses: | MIT |
Submitter: | 2bluesc |
Maintainer: | 2bluesc |
Last Packager: | 2bluesc |
Votes: | 20 |
Popularity: | 0.062057 |
First Submitted: | 2015-10-29 06:31 |
Last Updated: | 2021-04-04 17:44 |
Dependencies (9)
- python(python-dbg)
- python-b2sdk<2.0.0
- python-rst2ansi=0.1.5
- python-class-registry=3.0.5
- python-docutils>=0.16
- python-arrow>=0.8.0
- python-b2sdk>=1.0.0
- python-setuptools(make)
- python-setuptools-scm<6.0 (make)
Sources (1)
Kage-Yami commented on 2021-04-04 17:46
2bluesc commented on 2021-04-04 17:44
Kage-Yami commented on 2021-04-04 17:38
Looks like the same issue as we found on python-b2sdk
is affecting this package as well; turns out the timing of my builds were such that the new version of this wasn't visible yet when I originally reported, but a later build then failed.
Same pip
error:
ipha commented on 2021-04-04 14:49
New dep python-docutils is needed as of version 2.2+
Hoek commented on 2020-10-17 16:24
@2bluesc sorry I was mistaken. Somehow building the package using yay caused the build to error out because python-tqdm and python-logfury were missing, but I see they're in the package dependencies.I can't reproduce after reinstalling, everything seems to be fine :/
Backblaze B2 Synology
2bluesc commented on 2020-10-16 04:04
@hoek Could you elaborate on what dependencies are missing?
The dependencies in the upstream project are @ https://github.com/Backblaze/B2_Command_Line_Tool/blob/master/requirements.txt and are covered by this package and/or the b2sdk package.
And as always, patches to fix the issue(s) are welcome.
Hoek commented on 2020-10-15 16:20
@2bluesc could you please add the mentioned packages to the deps, this package is awesome, but broken for a year already :(
FabioLolix commented on 2020-03-19 00:14
@arichiardi your problem is with 'tageditor' not with 'backblaze-b2', by the way 'reflective-rapidjson' is in the AUR
arichiardi commented on 2020-03-18 21:35
Hi there, is anybody running into this one?
Building tageditor..> Making package: tageditor 3.3.4-1 (Wed 18 Mar 2020 02:36:32 PM PDT)> Checking runtime dependencies..> Checking buildtime dependencies..> Missing dependencies: -> reflective-rapidjson> ERROR: Could not resolve all dependencies.
JohnRobson commented on 2020-01-24 06:04
Must install the dependencies: python-b2sdk python-logfury python-funcsigs