(request)
该方法需自己写调用端来上传图片，该方法仅提供图床功能
    :param request:
    :return:
该方法需自己写调用端来上传图片，该方法仅提供图床功能
    :param request:
    :return:
该方法需自己写调用端来上传图片，该方法仅提供图床功能 : param request : : return :
def fileupload(request):
    """
    该方法需自己写调用端来上传图片，该方法仅提供图床功能
    :param request:
    :return:
    """
    if request.method == 'POST':
        sign = request.GET.get('sign', None)
        if not sign:
            return HttpResponseForbidden()
        if not sign == get_sha256(get_sha256(settings.SECRET_KEY)):
            return HttpResponseForbidden()
        response = []
        for filename in request.FILES:
            timestr = datetime.datetime.now().strftime('%Y/%m/%d')
            imgextensions = ['jpg', 'png', 'jpeg', 'bmp']
            fname = u''.join(str(filename))
            isimage = len([i for i in imgextensions if fname.find(i) >= 0]) > 0
            blogsetting = get_blog_setting()

            basepath = r'{basedir}/{type}/{timestr}'.format(
                basedir=blogsetting.resource_path,
                type='files' if not isimage else 'image',
                timestr=timestr)
            if settings.TESTING:
                basepath = settings.BASE_DIR + '/uploads'
            url = 'https://resource.lylinux.net/{type}/{timestr}/{filename}'.format(
                type='files' if not isimage else 'image', timestr=timestr, filename=filename)
            if not os.path.exists(basepath):
                os.makedirs(basepath)
            savepath = os.path.normpath(os.path.join(basepath, f"{uuid.uuid4().hex}{os.path.splitext(filename)[-1]}"))
            if not savepath.startswith(basepath):
                return HttpResponse("only for post")
            with open(savepath, 'wb+') as wfile:
                for chunk in request.FILES[filename].chunks():
                    wfile.write(chunk)
            if isimage:
                from PIL import Image
                image = Image.open(savepath)
                image.save(savepath, quality=20, optimize=True)
            response.append(url)
        return HttpResponse(response)

    else:
        return HttpResponse("only for post")
def fileupload ( request ) : if request . method == 'POST' : sign = request . GET . get ( 'sign' , None ) if not sign : return HttpResponseForbidden ( ) if not sign == get_sha256 ( get_sha256 ( settings . SECRET_KEY ) ) : return HttpResponseForbidden ( ) response = [ ] for filename in request . FILES : timestr = datetime . datetime . now ( ) . strftime ( '%Y/%m/%d' ) imgextensions = [ 'jpg' , 'png' , 'jpeg' , 'bmp' ] fname = u'' . join ( str ( filename ) ) isimage = len ( [ i for i in imgextensions if fname . find ( i ) >= 0 ] ) > 0 blogsetting = get_blog_setting ( ) basepath = r'{basedir}/{type}/{timestr}' . format ( basedir = blogsetting . resource_path , type = 'files' if not isimage else 'image' , timestr = timestr ) if settings . TESTING : basepath = settings . BASE_DIR + '/uploads' url = 'https://resource.lylinux.net/{type}/{timestr}/{filename}' . format ( type = 'files' if not isimage else 'image' , timestr = timestr , filename = filename ) if not os . path . exists ( basepath ) : os . makedirs ( basepath ) savepath = os . path . normpath ( os . path . join ( basepath , f"{uuid.uuid4().hex}{os.path.splitext(filename)[-1]}" ) ) if not savepath . startswith ( basepath ) : return HttpResponse ( "only for post" ) with open ( savepath , 'wb+' ) as wfile : for chunk in request . FILES [ filename ] . chunks ( ) : wfile . write ( chunk ) if isimage : from PIL import Image image = Image . open ( savepath ) image . save ( savepath , quality = 20 , optimize = True ) response . append ( url ) return HttpResponse ( response ) else : return HttpResponse ( "only for post" )