示例#1
0
def some_view(request):
    # Create the HttpResponse object with the appropriate PDF headers.
    response = HttpResponse(content_type='application/pdf')
    response['Content-Disposition'] = 'attachment; filename="somefilename.pdf"'

    buffer = BytesIO()

    # Create the PDF object, using the BytesIO object as its "file."
    p = canvas.Canvas(buffer)

    # Draw things on the PDF. Here's where the PDF generation happens.
    # See the ReportLab documentation for the full list of functionality.
    p.drawString(100, 100, "Hello world.")

    # Close the PDF object cleanly.
    p.showPage()
    p.save()

    # Get the value of the BytesIO buffer and write it to the response.
    pdf = buffer.getvalue()
    response.write(pdf)
    buffer.close()

    with open('/tmp/hello.world', 'w') as f:
        myfile = File(f)
        myfile.write('Hello World')
        upload(myfile, "test")



    return response
示例#2
0
def image_process(upload_pic):
    im = Image.open(StringIO(upload_pic.read()))

    new_upload, thumb_file, thumb_name = resize_upload_image(im, upload_pic)
    
    upload_path=upload(new_upload)

    thumb_path=upload(thumb_file)

    return upload_path, thumb_path
示例#3
0
 def save(self, *args, **kwargs):
     self.fileObj = ContentFile(self.content)
     upload(self.fileObj,
            name=self.key,
            bucket_name=self.bucket.name,
            key=settings.AWS_ACCESS_KEY_ID,
            secret=settings.AWS_SECRET_ACCESS_KEY,
            host=settings.BOTO_S3_HOST,
            expires=10,
            query_auth=True,
            replace=self.bucket.allow_file_replace)
     super(S3Object, self).save(*args, **kwargs)
示例#4
0
 def save(self, *args, **kwargs):
     self.fileObj = ContentFile(self.content)
     upload(self.fileObj,
                    name=self.key,
                    bucket_name=self.bucket.name,
                    key=settings.AWS_ACCESS_KEY_ID,
                    secret=settings.AWS_SECRET_ACCESS_KEY,
                    host=settings.BOTO_S3_HOST,
                    expires=10,
                    query_auth=True,
                    replace=self.bucket.allow_file_replace)
     super(S3Object, self).save(*args, **kwargs)
示例#5
0
def upload_csv(request):
	if request.method == 'POST':
		form = UploadFileForm(request.POST, request.FILES)
		data_url = upload(request.FILES['file'])
		if form.is_valid():
			data_url = upload(request.FILES['file'])
			print data_url
			print ("uploaded: ", request.FILES['file'])
			# handle_uploaded_file(request.FILES['file'])
			return HttpResponseRedirect('/repository/')
		else:
			print ("invalid form", form.errors)
	else:
		form = UploadFileForm()
	return render(request, 'upload.html', {'form':form})
示例#6
0
文件: views.py 项目: brianhwitte/fcf
def image_process(upload_pic):
    im = Image.open(StringIO(upload_pic.read()))

    location_data = get_exif(im)

    if location_data:
        location = make_location(location_data)
    else:
        location = Location.objects.filter(pk=1)[0]

    new_upload, thumb_file, thumb_name = resize_upload_image(im, upload_pic)
    
    upload_path=upload(new_upload)

    thumb_path=upload(thumb_file)

    return upload_path, thumb_path, location
示例#7
0
def upload_comic(series_id, file=None, file_url=None):
    """
    Given a series id and a file or a file url, upload the comic pages
    to s3 and create a new Comic instance in the given series.
    """
    # We need at least one of the arguments.
    if file is None and file_url is None:
        return None

    # If a file url is provided, download it to memory and get its file name.
    if file_url:
        req = requests.get(file_url, stream=True)
        d = req.headers['content-disposition']
        file_name = re.findall("filename=(.+)", d)
        file_name = file_name[0][:-1][1:]  # Remove double quotes.
        file = io.BytesIO(req.content)
        closing(req)
    # Otherwise simply take its file name.
    else:
        file_name = file.name

    # Determine whether it's a CBR or a CBZ and create a RarFile or a ZipFile.
    if file_name.endswith('.{}'.format(CBR)):
        cb_file = RarFile(file)
        cb_type = CBR
    elif file_name.endswith('.{}'.format(CBZ)):
        cb_file = ZipFile(file)
        cb_type = CBZ
    else:
        return None

    # Go through the CBZ/CBR pages and upload all of them to s3.
    page_urls = []
    for file_name in cb_file.namelist():
        if not file_name.lower().endswith(
                '.jpg') and not file_name.lower().endswith('.png'):
            continue
        image_url = upload(ContentFile(cb_file.read(file_name)),
                           name=file_name,
                           prefix=False,
                           bucket_name=False,
                           key=None,
                           secret=None,
                           host=None,
                           expires=0,
                           query_auth=False,
                           force_http=True,
                           policy=None)
        page_urls.append(image_url)

    # Create a comic.
    return Comic.objects.create(title=file_name.replace('.cbz', ''),
                                file_type=cb_type,
                                pages='|'.join(page_urls),
                                series_id=series_id)
示例#8
0
def upload_file(request): 
  if request.method=='GET' or request.method !='POST':
    form =UploadFileForm()
    return render(request, "employees/upload_file.html",{'form': form})
  
  form = UploadFileForm(request.POST, request.FILES)
  if form.is_valid():
    upload_path = upload(request.FILES['file'])
#    e = UserProfile(user=request.user)
#    e.photo = upload_path
# 
    print upload_path
    
  return HttpResponse("Uploaded")
示例#9
0
def upload_file(request):
    if request.method == 'GET' or request.method != 'POST':
        form = UploadFileForm()
        return render(request, "jotto/profilepic.html", {'form': form})
    form = UploadFileForm(request.POST, request.FILES)
    if form.is_valid():
        print request.FILES['file']
        upload_path = upload(request.FILES['file'])
        print upload_path
        up = User_Profile.objects.get(user=request.user)

        up.profilePic = upload_path
        up.save()

    return redirect('/leaderboard')
示例#10
0
def upload_file(request):
	if request.method == 'GET' or request.method != 'POST': 
		form = UploadFileForm()                                          
		return render(request, "jotto/profilepic.html", {'form': form})
	form = UploadFileForm(request.POST, request.FILES)
	if form.is_valid():
		print request.FILES['file']
		upload_path = upload(request.FILES['file'])
		print upload_path
		up = User_Profile.objects.get(user=request.user)
		
		up.profilePic = upload_path
		up.save()

	return redirect('/leaderboard')
示例#11
0
def upload_file(request):
	if request.method == 'POST':
		form = UploadFileForm(request.POST, request.FILES)
		if form.is_valid():
			print request.FILES['file']
			data_url = upload(request.FILES['file'])
			#create new django model
			d = Data.objects.create(owner=request.user)
			d.name = request.POST['name']
			d.url = data_url
			d.description =request.POST['description']
			d.save()
		return HttpResponseRedirect('/repository/')
	else:
		form = UploadFileForm()
	return render(request,'upload.html', {'form': form})
示例#12
0
def upload_file(request):
	if request.method == 'GET' or request.method != 'POST':
		form = UploadFileForm()
		return render(request,'geoquiz/upload_file.html', {'form':form})

	form = UploadFileForm(request.POST, request.FILES)
	if form.is_valid():
		print "request.Files['file']:", request.FILES['file']
		#NB this is the url where the image can be found
		upload_path = upload(request.FILES['file'])
		#upload() derived from django_boto.s3 import upload
	print "upload path:", upload_path

	response = HttpResponse()

	response.write('<h3>File successfully uploaded</h3>')
	response.write('<p>Click <a href="/">here</a> to go back to the home page</p>')

	return response
示例#13
0
def handle_uploaded_file(f):
    upload(f, prefix=False, bucket_name=False, key=None, secret=None)
    with open('some/file/name.txt', 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)
def handle_uploaded_file(f):
    upload(f, prefix=False, bucket_name=False, key=None, secret=None)
    with open('some/file/name.txt', 'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)