Skip to main content

Django Direct File Transfer From Server

Project description

Django OSS File Field

django-oss-file-field provides a Django Direct File Transfer From Server.

Features

  • Django Direct File Transfer From Server to OSS

  • Flexible File Size/Type Limitation

  • Progress Bar Display

  • Works in Python 3

Installation

  • Install

$ pip install ossFileField
  • Add 'ossFileField' to your INSTALLED_APPS setting

Authentication settings

Use the following settings to authenticate with AliCloud OSS.

# AliCloud Access Key ID
OSS_ACCESS_KEY_ID = <Your Access Key ID>

# AliCloud Access Key Secret
OSS_ACCESS_KEY_SECRET = <Your Access Key Secret>

# OSS Bucket Name
OSS_BUCKET_NAME = <Your OSS Bucket name>

# AliCloud Bucket Host format: http://bucket_name.endpoint eg: http://test.oss-cn-hangzhou.aliyuncs.com
OSS_BUCKET_HOST = <Your Oss Bucket Host>

# AliCloud Token Expire Time
OSS_EXPIRE_TIME = <Token Expire Time>

# Get OSS Token Routing
OSS_TOKEN_ROUTE = <Get OSS Token Route>

# Oss Bucket Proxy URL
OSS_PROXY_URL = <OSS Bucket Proxy URL>

# Server URL
SERVER_URL = <Your App Server Domain URL>

# Upload To Oss Dir(end of slash)
UPLOAD_DIR = <Upload OSS Dir>

Get OSS Token

Register the route in the url file to get the token

# urls.py
from django.conf.urls import url

from . import views

urlpatterns = [
    url(r'^get_oss_token$', views.get_oss_token, name='get_oss_token'),
]
# views.py
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from ossFileField.utils import OssToken

@login_required
@require_http_methods(["GET"])
def get_oss_token(request):
    oss_token = OssToken.get_oss_key()
    return HttpResponse(oss_token)

Usage

models.py import OssFileField

# models.py
from ossFileField import OssFileField


class Images(models.Model):
    name = models.CharField(max_length=64, blank=False)
    oss_file = OssFileField(prefix='test/', file_type='image', max_file_size='20m', blank=False)

Version

1.0.3

  • Support models prefix attribute((end of slash))

  • Support limit uploaded file size

  • The uploaded file name includes the file origin name and file size

1.0.4

  • Support public bucket

  • Support file name with spaces

1.0.5

  • Support chinese file name

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ossFileField-1.0.5.tar.gz (256.2 kB view details)

Uploaded Source

File details

Details for the file ossFileField-1.0.5.tar.gz.

File metadata

  • Download URL: ossFileField-1.0.5.tar.gz
  • Upload date:
  • Size: 256.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.4

File hashes

Hashes for ossFileField-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e6e9d7ba6528a4abf0d17f9d4650ac1d826fe3b04fb9251ab83b2f80b767cbed
MD5 91e5c88e1f849fb8f4cb140444b79982
BLAKE2b-256 c9b028920146fab7ce6ca11127625adfd22a10112b94b5aa3e9532880fdfeb73

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page