标签: image-upload

正在上传图片文件

你能帮我把django表格上的图片上传工作吗?

Models.py

class User_Profile(models.Model):
    user = models.OneToOneField(User, unique=True, related_name='profile')
    photo  = models.ImageField(upload_to = 'profiles/', null=True, blank=True)
Run Code Online (Sandbox Code Playgroud)

Forms.py

class ProfileForm(forms.ModelForm):
        class Meta:
            model = User_Profile
            exclude = ('user')
Run Code Online (Sandbox Code Playgroud)

Views.py

    if request.method == 'POST':
        profile_form = ProfileForm(request.POST, instance=request.user.profile)

        if profile_form.is_valid():
            profile_form.save()
            return HttpResponseRedirect('/panel/correct/')

    else:
        profile_form = ProfileForm(instance=request.user.profile)
Run Code Online (Sandbox Code Playgroud)

我的html表单已包含 enctype="multipart/form-data"

django file-upload image-upload

9
推荐指数
2
解决办法
2万
查看次数

如何在POSTMAN中使用raw上传图像?

我正在尝试使用POSTMAN上传图像.我成功使用了表单数据,但没有使用原始JSON格式传递数据.

通过POSTMAN中的表单数据请求:

在此输入图像描述

请求通过curl:

curl -X POST -H "Content-Type:multipart/form-data" -F "profile_image=@/home/shivani/Pictures/Wallpapers/8018.jpg" http://127.0.0.1:8000/api/users/1/image/
{"message":"Image Uploaded successfully.","profile_image":"http://res.cloudinary.com/aubergine-solutions/image/upload/v1430204993/w0oxhv6beaxd14twrxmi.jpg"}~ 
Run Code Online (Sandbox Code Playgroud)

当我发送原始请求时:

在此输入图像描述

虽然我在Django设置中添加了MultiPartParser,但是出现以下错误:

在此输入图像描述

任何人都可以帮忙解决这个问题吗?

django request image-upload postman

8
推荐指数
1
解决办法
2万
查看次数

图像上传CURL命令到PHP Curl

我是PHP CURL的新手,并试图调用API来进行图像上传(一次多个文件).API文档在CURL中给出了以下示例.我已经测试过,它正在运行.

curl -H "Authorization: Bearer 123456789" -i -X POST -F "whitespace=1" \
 -F "imageData[]=@/path/to/images/milk.jpg" \
 -F "imageData[]=@/path/to/images/peas.jpg" \
 https://mytestapi.com/1.0/uploadimages
Run Code Online (Sandbox Code Playgroud)

现在我需要将其转换为PHP Curl.出于某种原因,我总是得到错误"imageData"param无效.有人可以请帮助

$token = '123456789';
$imgUrl = 'https://mytestapi.com/1.0/uploadimages';


$data_to_post = array();
$data_to_post['whitespace'] = '1';
$data_to_post['imageData[]'] = '@/path/to/images/milk.jpg';
$data_to_post['imageData[]'] = '@/path/to/images/peas.jpg';


$curl = curl_init($imgUrl);
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Authorization: Bearer '.$token]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl,CURLOPT_POST, 1);
curl_setopt($curl,CURLOPT_POSTFIELDS, $data_to_post);
$data = json_decode(curl_exec($curl));
$responseCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

var_dump($data);
Run Code Online (Sandbox Code Playgroud)

php curl libcurl image-upload

8
推荐指数
1
解决办法
1224
查看次数

如何将图像从Flash传递到ASP.NET?

快速版:

如何将用户浏览器上生成的图像恢复到服务器?

目前的计划如下:

  1. Flash开发人员将位图转换为JPEG
  2. 然后他将JPEG发布到网站上的页面.
  3. 我想我可以创建一个WebService将使用a StreamReader来阅读帖子并将其保存为文件.

那会有用吗?这样做的任何现有代码/样本?

我想我们应该能够查看代码,以便将任何文件上传到ASP.NET.

asp.net flash actionscript-3 image-upload

7
推荐指数
1
解决办法
1万
查看次数

如何使用fineuploader

我希望将fineuploader集成到我的JQuery Mobile应用程序中.作为一个起点,我尝试使用fineuploader.com上提供的默认模板来熟悉自己.

我从github下载了最新的fineuploader副本. 我已经通过猜测给出了.js文件的来源,因为我找不到关于要引用哪些文件以便使用fineuploader jquery插件的明确文档.

默认模板不起作用,我相信我没有引用相应的文件?有人可以告诉我可能做错了什么吗?

以下是我在fineuploader.com上使用的默认模板.

<!DOCTYPE html>

<html>
  <head>

      <link href="fine-uploader-master/client/fineuploader.css" rel="stylesheet"/>

  </head>
  <body>

    <!-- The element where Fine Uploader will exist. -->
    <div id="fine-uploader">
    </div>

    <!-- jQuery version 1.10.x (if you are using the jQuery plugin -->
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>

    <!-- Fine Uploader-jQuery -->
    <script src="fine-uploader-master/client/js/jquery-plugin.js" type="text/javascript"></script>
    <script src="fine-uploader-master/client/js/uploader.js" type="text/javascript"></script>
    <script>
    // Wait until the DOM is 'ready'
    $(document).ready(function () {
        $("#fine-uploader").fineUploader({
            debug: true,
            request: {
                endpoint: '/uploads' …
Run Code Online (Sandbox Code Playgroud)

jquery file-upload image-upload jquery-mobile fine-uploader

7
推荐指数
1
解决办法
6300
查看次数

如何替换已弃用的 okhttp.RequestBody.create()

我尝试使用Retrofit 2OkHttp3将图像从 Android 应用程序上传到 Django 服务器。为此,我曾经RequestBody使用以下几行创建一个实例:

RequestBody requestImageFile =
                    // NOW this call is DEPRECATED
                    RequestBody.create(
                            MediaType.parse("image/*"),

                            // a File instance created via the path string to the image
                            imageFile
                    );
Run Code Online (Sandbox Code Playgroud)

我在下一个方法调用中使用了前一个实例作为参数:

// MultipartBody.Part is used to send also the actual file name
MultipartBody.Part image = MultipartBody.Part.createFormData("image", imageFile.getName(), requestImageFile);
Run Code Online (Sandbox Code Playgroud)

最后,我启动了 Retrofit 界面来完成剩下的工作:

// finally, execute the request
Call<ResponseBody> call = service.upload(image);
call.enqueue(new Callback<ResponseBody>() {
     @Override
     public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            Log.v("Upload", "success"); …
Run Code Online (Sandbox Code Playgroud)

android image-upload okhttp retrofit2

7
推荐指数
3
解决办法
7489
查看次数

无服务器我将图像上传到 S3 在部署后损坏,仅本地工作

我尝试将图像上传到 S3 使用serverless和 NodeJS,但上传后出现问题。在本地使用中,serverless-offline一切都像冠军一样工作,但部署后我收到此错误。然后我尝试拦截并检测发生了什么并看到这个结果:

图像主体中出现了一些奇怪的字符,例如<0x0a> 0x01 0x04

在此输入图像描述

我也尝试过使用serverless-apigw-binary,但运气不好。

image-upload aws-lambda serverless

7
推荐指数
2
解决办法
3665
查看次数

dropzone.js和ASP.NET MVC文件发布是否为空?

我正在尝试使用dropzone.js在我的ASP.NET MVC应用程序中上传图像.我能够以编程方式设置dropzone,单击它,选择图像,当我在文件对话框中单击"打开"时,控制器中将触发正确的操作.但是,HttpPostedFileBase总是返回null,因此我无法对图像做任何事情.但是,在客户端,它会正确显示图像缩略图,尽管我无法在服务器端获取它.

这是HTML:

<div style="float:left;margin-right:2px;" id="mainImage">
    <img src="/images/AddImage_button.png" class="dz-message" />
</div>
Run Code Online (Sandbox Code Playgroud)

这是我在doc准备好之后调用的js代码:

var myDropzone = new Dropzone("div#mainImage", { url: "/Market/UploadImage" });
Run Code Online (Sandbox Code Playgroud)

这是控制器内部的动作调用:

public ContentResult UploadImage(HttpPostedFileBase imageFile)
{

    if (imageFile == null || imageFile.ContentLength == 0)
    {
    //.....
    }
}
Run Code Online (Sandbox Code Playgroud)

操作被命中但imageFile为null.有没有人有任何想法?顺便说一句,"dz-message"类被添加到dropzone内的图像占位符中,因为在此之前它不可点击.我在某个地方读到了这个问题的修复工具.

任何想法为什么我为imageFile得到null?

asp.net-mvc image-uploading image-upload dropzone.js

6
推荐指数
1
解决办法
2791
查看次数

Amazon S3 .NET:上传 Base64 图像数据?

我正在尝试将图像转换为 base64,并尝试使用 C# 将其上传到 AWS S3。我不断收到远程服务器未找到异常。但我可以以编程方式登录并列出我拥有的存储桶。您能确定出什么问题了吗?

    static void Main(string[] args)
    {

        string configaccess = ConfigurationManager.AppSettings["AWSAccesskey"];
        string configsecret = ConfigurationManager.AppSettings["AWSSecretkey"];

        var s3Client = new AmazonS3Client(
            configaccess,
            configsecret,
            RegionEndpoint.USEast1
        );

        Byte[] bArray = File.ReadAllBytes("path/foo.jpg");
        String base64String = Convert.ToBase64String(bArray);

        try
        {
            byte[] bytes = Convert.FromBase64String(base64String);

            using (s3Client)
            {
                var request = new PutObjectRequest
                {
                    BucketName = "bucketName",
                    CannedACL = S3CannedACL.PublicRead,
                    Key = string.Format("bucketName/{0}", "foo.jpg")
                };
                using (var ms = new MemoryStream(bytes))
                {
                    request.InputStream = ms;
                    s3Client.PutObject(request);
                }
            }
        }
        catch (Exception ex)
        { …
Run Code Online (Sandbox Code Playgroud)

c# amazon-s3 image-upload

6
推荐指数
1
解决办法
6256
查看次数

图像上传和基于CreateView的视图

我希望能够使用CreateView和ModelForm上传图像文件但我无法使其工作 - 看起来表单在选择文件后不会绑定任何文件数据.以下是视图的当前内容:

class AddContentForm(forms.ModelForm):
    class Meta:
        model = Media


class AddContentView(CreateView):
    template_name = 'simple_admin/add_content.html'
    form_class = AddContentForm

    def get_success_url(self):
        return u'/opettajat/subcategory/{0}/{1}/'.format(self.kwargs['subcat_name'].decode('utf-8'), self.kwargs['subcat_id'].decode('utf-8'))


    def form_valid(self, form):
        isvalid = super(AddContentView, self).form_valid(form)
        s = Subcategory.objects.get(pk=self.kwargs['subcat_id'].encode('utf-8'))
        if self.request.POST.get('image'):
            image = form.cleaned_data['image']
            title = form.cleaned_data['art_title'].encode('utf-8')
            year_of_creation = form.cleaned_data['year_of_creation']
            m = Media.objects.get_or_create(image=image, art_title=title, year_of_creation=year_of_creation)[0]
            s.media.add(m)
            s.save()
       return isvalid

    def get_context_data(self, **kwargs):
        context = super(AddContentView, self).get_context_data(**kwargs)
        context['subcategory_name'] = self.kwargs['subcat_name'].encode('utf-8')
        context['subcategory_id'] = self.kwargs['subcat_id'].encode('utf-8')
        return context

     @method_decorator(login_required)
     def dispatch(self, request, *args, **kwargs):
        return super(AddContentView, self).dispatch(request, *args, **kwargs)
Run Code Online (Sandbox Code Playgroud)

有人可以帮忙吗?可以理解基于类的图像上载视图的简单示例.

django image-upload class-based-views

5
推荐指数
1
解决办法
5406
查看次数