Beispiel #1
0
def upload_image(request):
    if request.method == "POST":
        if len(request.FILES) > 0:
            filename = save_file(request.FILES['picture'])

            width, height = get_image_size(filename)

            picture = Picture()
            picture.picture_url = filename
            picture.posted_on = datetime.datetime.now()
            picture.text = "testing hardstyle"
            picture.published = True
            picture.width = width
            picture.height = height
            picture.save()

            response_data = {}
            response_data['image_id'] = picture.pk

            return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
Beispiel #2
0
def upload(request):
    if request.method == "POST":
        
        filename = str(int(random.random() * 1000000)) + str(int(time.time())) + ".jpg"
        fh = open(settings.MEDIA_ROOT + filename , "wb")
        fh.write(request.POST['base64_image'].decode('base64'))
        fh.close()
        
        width, height = get_image_size(filename)

        picture = Picture()
        picture.picture_url = filename
        picture.posted_on = datetime.datetime.now()
        picture.width = width
        picture.height = height
        picture.text = "testing hardstyle"
        picture.save()

        response_data = {}
        response_data['image_id'] = picture.pk

        return HttpResponse(simplejson.dumps(response_data), mimetype="application/json")
    else:
        return HttpResponseRedirect("/")