首页 \ 问答 \ 如何从AFNETWORKING POST获取参数(How to GET parameters from AFNETWORKING POST)

如何从AFNETWORKING POST获取参数(How to GET parameters from AFNETWORKING POST)

我怎样才能从Swift获取参数值,文件上传已经工作,我试过$ _GET [“familyId”],但它没有工作?

迅速:

    let manager = AFHTTPRequestOperationManager()
    let url = "http://localhost/test/upload.php"
    var fileURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("test_1", ofType: "mov")!)
    var params = [
        "familyId":locationd,
        "contentBody" : "Some body content for the test application",
        "name" : "the name/title",
        "typeOfContent":"photo"
    ]

    manager.POST( url, parameters: params,
        constructingBodyWithBlock: { (data: AFMultipartFormData!) in
            println("")
            var res = data.appendPartWithFileURL(fileURL, name: "fileToUpload", error: nil)
            println("was file added properly to the body? \(res)")
        },
        success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
            println("Yes thies was a success")
        },
        failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
            println("We got an error here.. \(error.localizedDescription)")
    })

PHP:

 $target_dir = "uploads/";
 $target_dir = $target_dir . basename($_FILES["fileToUpload"]["name"]);

 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir)) {
echo json_encode([
    $user_info;
    "Message" => "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.",
    "Status" => "OK",
     ]);

How can I get the the parameter values from Swift, the file upload is already working, I've tried $_GET["familyId"], but it didn't work?

Swift:

    let manager = AFHTTPRequestOperationManager()
    let url = "http://localhost/test/upload.php"
    var fileURL = NSURL.fileURLWithPath(NSBundle.mainBundle().pathForResource("test_1", ofType: "mov")!)
    var params = [
        "familyId":locationd,
        "contentBody" : "Some body content for the test application",
        "name" : "the name/title",
        "typeOfContent":"photo"
    ]

    manager.POST( url, parameters: params,
        constructingBodyWithBlock: { (data: AFMultipartFormData!) in
            println("")
            var res = data.appendPartWithFileURL(fileURL, name: "fileToUpload", error: nil)
            println("was file added properly to the body? \(res)")
        },
        success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) in
            println("Yes thies was a success")
        },
        failure: { (operation: AFHTTPRequestOperation!, error: NSError!) in
            println("We got an error here.. \(error.localizedDescription)")
    })

PHP:

 $target_dir = "uploads/";
 $target_dir = $target_dir . basename($_FILES["fileToUpload"]["name"]);

 if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_dir)) {
echo json_encode([
    $user_info;
    "Message" => "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.",
    "Status" => "OK",
     ]);

原文:https://stackoverflow.com/questions/29704636
更新时间:2021-08-02 13:08

最满意答案

在使用Hadoop的过程中,很容易通过FileSystem类的API来读取HDFS中的文件内容,读取内容的过程是怎样的呢?今天来分析客户端读取HDFS文件的过程,下面的一个小程序完成的功能是读取HDFS中某个目录下的文件内容,然后输出到控制台,代码如下:

[java] view plain copy 
public class LoadDataFromHDFS {  
    public static void main(String[] args) throws IOException {  
        new LoadDataFromHDFS().loadFromHdfs("hdfs://localhost:9000/user/wordcount/");  
    }  

    public void loadFromHdfs(String hdfsPath) throws IOException {  
        Configuration conf = new Configuration();  

        Path hdfs = new Path(hdfsPath);  

        FileSystem in = FileSystem.get(conf);  
        //in = FileSystem.get(URI.create(hdfsPath), conf);//这两行都会创建一个DistributedFileSystem对象  

        FileStatus[] status = in.listStatus(hdfs);  
        for(int i = 0; i < status.length; i++) {  
            byte[] buff = new byte[1024];  
            FSDataInputStream inputStream = in.open(status[i].getPath());  
            while(inputStream.read(buff) > 0) {  
                System.out.print(new String(buff));  
            }  
            inputStream.close();  
        }  
    }  
}  

FileSystem in = FileSystem.get(conf)这行代码创建一个DistributedFileSystem,如果直接传入一个Configuration类型的参数,那么默认会读取属性fs.default.name的值,根据这个属性的值创建对应的FileSystem子类对象,如果没有配置fs.default.name属性的值,那么默认创建一个org.apache.hadoop.fs.LocalFileSystem类型的对象。但是这里是要读取HDFS中的文件,所以在core-site.xml文件中配置fs.default.name属性的值为hdfs://localhost:9000,这样FileSystem.get(conf)返回的才是一个DistributedFileSystem类的对象。 还有一种创建DistributedFileSystem这种指定文件系统类型对像的方法是使用FileSystem.get(Configuration conf)的一个重载方法FileSystem.get(URI uri, Configuration),其实调用第一个方法时在FileSystem类中先读取conf中的属性fs.default.name的值,再调用的FileSystem.get(URI uri, Configuration)方法。

其他回答

首先,不得不说,hadoop发展到现在这个阶段,代码已经变得非常庞大臃肿,如果你直接阅读最新版本的源代码,难度比较大,需要足够的耐心和时间,所以,如果你觉得认真一次,认真阅读一次hadoop源代码,一定要有足够的心理准备和时间预期。 其次,

相关问答

更多
  • hadoop hdfs目录[2022-03-28]

    移动目录的命令很简单啊,跟Linux shell的命令差不多: hdfs dfs -mv 被移动的目录A 目标目录B 直接移动就行,不知道能否解决你的问题。
  • 配置过程中出先的问题: 在eclipse中无法向文件HDFS文件系统写入的问题,这将直接导致eclipse下编写的程序不能在hadoop上运行。 打开conf/hdfs-site.xml,找到dfs.permissions属性修改为false(默认为true)OK了。 dfs.permissions false 改完需要重启HDFS; 最简单的就是刚才说的登录桌面启动eclipse的用户本身就是hadoop的管理员
  • hadoop hdfs的问题[2021-10-30]

    最下面那张图里环境变量设置的那一行多了一个$符号 export JAVA_HOME=/usr/java/jdk1.6.0_35
  • 在使用Hadoop的过程中,很容易通过FileSystem类的API来读取HDFS中的文件内容,读取内容的过程是怎样的呢?今天来分析客户端读取HDFS文件的过程,下面的一个小程序完成的功能是读取HDFS中某个目录下的文件内容,然后输出到控制台,代码如下: [java] view plain copy public class LoadDataFromHDFS { public static void main(String[] args) throws IOException { new LoadDataF ...
  • 默认情况下,Hadoop将使用本地模式。 您可能需要在$HADOOP_HOME/conf/core-site.xml中将fs.default.name设置为hdfs://localhost.localdomain:8020/ 。 为此,请将其添加到core-site.xml : fs.default.name hdfs://localhost.localdomain:8020/ Accumulo ...
  • 如何查看或查询元数据? 您可以在Offline Image Viewer的帮助下完成此操作。 它是一种将fsimage文件的内容转储为人类可读格式的工具,以便允许离线分析和检查Hadoop集群的命名空间。 用法: bin / hdfs oiv -i fsimage -o fsimage.txt 你可以在这里找到更多相关信息 。 我怎么看 - 我的输入文件是如何被阻止和分发的? 最简单的方法是将您的Web浏览器指向HDFS webUI ,即namemnode_machine:50070 。 然后浏览到相关文件 ...
  • 实现自己的DFS接口并使其与hadoop一起使用相对简单。 您所需要的只是文件和目录的文件系统概念与您的存储之间的某种逻辑映射。 在NoSQL的情况下(如果我假设KeyValue),您应该决定如何表示目录。 您可以执行一些特殊节点,也可以将路径放入密钥。 另一个决策点 - 决定您是否关心数据位置 关于文档,我认为s3n DFS实现的来源最好从一开始。 我认为关闭的例子是由DataStax完成的Cassandra上的Hadoop http://www.datastax.com/ 另一个例子(我们稍后做的事情) ...
  • Apache Spark独立于Hadoop。 Spark允许您使用不同的数据源(包括HDFS),并且能够在独立群集中运行,或者使用现有的资源管理框架(例如,YARN,Mesos)。 因此,如果您只对Spark感兴趣,则无需安装Hadoop。 Apache Spark is independent from Hadoop. Spark allows you to use different sources of data (incl. HDFS) and is capable of running eithe ...
  • 绝对可能。 不要认为Hadoop是一个可安装的程序,它只是由一群在集群内不同节点上运行的java进程组成。 如果你使用hadoop tar ball,你可以只运行NameNode和DataNodes进程,如果你只想要HDFS。 如果您使用其他hadoop发行版(例如HDP),我认为HDFS和mapreduce来自不同的rpm软件包,但安装两个rpm软件包都有害。 如果您只需要HDFS,请再次运行NameNode和DataNodes。 Absolutely possible. Don't think Hado ...
  • Mappers从InputFormat的实现中读取输入数据。 大多数实现都来自FileInputFormat ,后者从本地计算机或HDFS读取数据。 (默认情况下,数据从HDFS读取,mapreduce作业的结果也存储在HDFS中。)当您希望从备用数据源读取数据而不是HDFS时,可以编写自定义InputFormat 。 TableInputFormat将直接从HBase读取数据记录, DBInputFormat将访问关系数据库中的数据。 您还可以想象一个系统,在特定端口上通过网络将数据流式传输到每台计算机; ...

相关文章

更多

最新问答

更多
  • 获取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的基本操作命令。。。