AFNetworking 2.0多部分/表格数据上传到mySQL(AFNetworking 2.0 multipart/form-data upload to mySQL)
我尝试过很多东西,但似乎无法让它发挥作用。 我可以通过UITextField将文本上传到mySQL数据库,我可以单独通过UIImageView上传图像但是当我尝试将它们放在一起时它不起作用:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil]; NSDictionary *parameters = @{@"new": self.enter}; NSData *imageData = UIImageJPEGRepresentation(self.uploadImage.image, 0.5); [manager POST:@"http://emily-ip.com/write.php" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"image" fileName:@"photo.jpg" mimeType:@"image/jpeg"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];
这段代码给了我错误:
"The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fabeb081660
所以我把它放进去:
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
这会上传图片,但不会上传从文本字段输入的文本,这是我得到的输出:
Success: <4572726f 72> Success: <53756363 65737366 756c>
我看了这么多帖子但我找不到问题。 无论如何,我认为它与文本字段有关。 有人可以帮我修复代码吗?
I have tried many things but I can't seem to get it working. I can upload text through a UITextField to the mySQL database and I can upload an image through UIImageView separately but when I try to put them together it does not work:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",@"application/json",nil]; NSDictionary *parameters = @{@"new": self.enter}; NSData *imageData = UIImageJPEGRepresentation(self.uploadImage.image, 0.5); [manager POST:@"http://emily-ip.com/write.php" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [formData appendPartWithFileData:imageData name:@"image" fileName:@"photo.jpg" mimeType:@"image/jpeg"]; } success:^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"Success: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"Error: %@", error); }];
This code gives me the error:
"The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x7fabeb081660
So I put this in:
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
This uploads the image but does not upload the text entered from the text field and this is the output I get:
Success: <4572726f 72> Success: <53756363 65737366 756c>
I have looked at so many posts but I can't find the problem. I think it is with the text field anyway. Can someone please help me fix the code?
原文:https://stackoverflow.com/questions/31558334
最满意答案
问题是我的执行声明:
execute 'git clone git@github.com:username/my_gem.git', gem_path
我改成了
execute "git clone git@github.com:username/my_gem.git #{gem_path}"
它现在按预期工作。
The issue was my execute statement:
execute 'git clone git@github.com:username/my_gem.git', gem_path
I changed it to
execute "git clone git@github.com:username/my_gem.git #{gem_path}"
and it is working as expected now.
相关问答
更多-
我的猜测是,因为您手动在CI环境中安装Capistrano Gems,所以存在版本不匹配。 如果您在CI服务器上运行bundle install和bundle exec ,或者固定安装的版本,它可能会开始工作。 我用过的一个解决方案是将所有必需的部署gem添加到我的Gemfile中的一个:deployment组中。 然后,您需要将以下内容添加到您的deploy.rb : set :bundle_without, %w{development test deployment}.join(' ') 然后将您的 ...
-
问题是我的执行声明: execute 'git clone git@github.com:username/my_gem.git', gem_path 我改成了 execute "git clone git@github.com:username/my_gem.git #{gem_path}" 它现在按预期工作。 The issue was my execute statement: execute 'git clone git@github.com:username/my_gem.git', gem_ ...
-
每当Gem无法在Capistrano正确运行“bundle exec”(Whenever Gem Fails to Run “bundle exec” Correctly in Capistrano)[2021-10-07]
事实证明,有几个问题需要解决: 每当〜> 0.8引入Capistrano角色的错误 每当cap任务在bundle:install之前触发(这在您的代码中已得到证实) 在此处查看问题: https : //github.com/javan/whenever/issues/275并在此处: https : //github.com/javan/whenever/issues/269 要解决这个问题,你很可能需要 更新服务器上的bundler(-v 1.2.3) 在本地更新打包程序 更新到最新的每当(-v 0.8 ... -
git clone repo.git git remote remove origin //因为你想完全删除它。 手动在Github上创建一个新的存储库。 git remote add origin git@github.com:user_name/new_repo.git git push -u origin HEAD git clone repo.git git remote remove origin // Because you want to remove it completely. Creat ...
-
Capistrano为每个版本的realeases创建一个新的子目录 horse:releases xxx$ ls -lart total 0 drwxrwxr-x 22 xxx staff 748 Jun 26 20:08 20120626180809 drwxrwxr-x 22 xxx staff 748 Jun 26 20:11 20120626181103 drwxrwxr-x 22 xxx staff 748 Jun 26 20:29 20120626182908 drwxrwx ...
-
用git lfs clone以光速git lfs clone 如果您拥有一个非常大的存储库,特别是如果您使用的是Windows,那么您肯定希望利用的新功能是专用的LFS克隆命令: git lfs clone ssh://git@mybb-server.com:7999/lfs/repo.git my-clone git lfs clone命令的运行方式与git clone完全相同,并且具有相同的参数,但有一个重要区别:它快得多! 根据您拥有的文件数量,它实际上可以快10倍以上。 阅读本文以了解git lfs ...
-
为什么不使用比密码更安全的东西来简化生活? 没有密码的ssh密钥将更加安全,而且根本不会提示。 如果它必须是100%自包含的,那么考虑让脚本输出SSH密钥,使用一次,然后将其删除。 (这应该保持您的安全状况不变:密码在脚本中是有效的,这对您来说是可接受的。) # Output SSH key for no-password login. (Could use mktemp instead) cat > /tmp/ssh_key.$$ <最后,主要问题是我需要正确设置代理转发。 我是用它做的 Host * ForwardAgent yes 在~/.ssh/config那我和我决定使用root作为用户来设置大多数的playbook资料。 Root不需要切换到sudo。 对于像克隆这样的部分,我可以使用用户laravel,因为它可以访问webroot作为所有者,并且也可以使用。 所以也不需要sudo。 在Ansible创建sudo用户之后,我还没有尝试切换到sudo。 对这一切仍然是新的。 但取得了进展。 我相信主机转发提示会帮助很多人。 ...负责定义要部署的目录的参数是:deploy_to 。 因此,为了将Capistrano部署到/var/www/html/web_app/您需要相应地配置它。 在下面set :keep_releases, 2将:deploy_to参数设置为/var/www/html/web_app/ 。 你的deploy.rb文件如下所示: set :application, "hunter" set :repo_url, "git@bitbucket.org:*****.git" # Default value for k ...看起来不是git,它的SSH。 您需要在.ssh/authorized_keys文件中指定密钥,即公钥btw。 私钥将存储在用户计算机上。 It's not git who is looking, its SSH. You need to specify the keys in the .ssh/authorized_keys file, that is the public key btw. The private key will be stored on the users machine.
相关文章
更多- mysql问题
- hadoop 2.0--YARN
- struts 2.0
- Mysql删除binlog(安全清理)
- Apache Hadoop 2.0 Alpha 发布
- Solr与Mysql集成指南
- OAuth 2.0 四种角色
- 【摘录】NoSQL进入2.0时代 10大知名项目盘点
- 关于netbeans和mysql的问题
- Solr与Mysql集成指南
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。