首页 \ 问答 \ Alamofire 4文件上传参数问题(Alamofire 4 File Upload Parameter issue)

Alamofire 4文件上传参数问题(Alamofire 4 File Upload Parameter issue)

请看看邮递员POSTMAN成功结果的图片,但代码无法运行我错过了一些东西,请帮助我

 var parameters = [String: String]()
        parameters = [
            "profile_image": "imagefile"
        ]

        let headers: HTTPHeaders = [
            "Accept": "application/json"
        ]

        let url = "http://******/public/api/v1/profile/update-picture?api_token=" + "aySlC26ZTHtlnS0lhUpdghxkd9gKJBLXLYFUO2Jidmiisoka9iFIicwRIZFx"
        let completeUrl = URL(string:url)!

        let imageData = UIImageJPEGRepresentation(chosenImage!, 1)
        print ("image data:: \(imageData)")
        print ("chosenImage:: \(chosenImage)")

//        Alamofire.upload(imageData!, to: completeUrl).response { response in
//            print (response)
//        }

        Alamofire.upload(
            multipartFormData: { 
                multipartFormData in
                multipartFormData.append(imageData!,
                                         withName: "imagefile",
                                         fileName: "image.jpg",
                                         mimeType: "image/jpeg")
                for (key, value) in parameters {
                    multipartFormData.append(value.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!, withName: key)
                }
        },
            to: completeUrl,
            headers: headers,
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON{ response in
                        print(response)
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }
            }
        )

邮差回复成功的邮差,但有头问题,你能指出我犯的愚蠢的错误


Plese have a look at the pic here from postman POSTMAN success result but the code does not run I am missing something please help me out

 var parameters = [String: String]()
        parameters = [
            "profile_image": "imagefile"
        ]

        let headers: HTTPHeaders = [
            "Accept": "application/json"
        ]

        let url = "http://******/public/api/v1/profile/update-picture?api_token=" + "aySlC26ZTHtlnS0lhUpdghxkd9gKJBLXLYFUO2Jidmiisoka9iFIicwRIZFx"
        let completeUrl = URL(string:url)!

        let imageData = UIImageJPEGRepresentation(chosenImage!, 1)
        print ("image data:: \(imageData)")
        print ("chosenImage:: \(chosenImage)")

//        Alamofire.upload(imageData!, to: completeUrl).response { response in
//            print (response)
//        }

        Alamofire.upload(
            multipartFormData: { 
                multipartFormData in
                multipartFormData.append(imageData!,
                                         withName: "imagefile",
                                         fileName: "image.jpg",
                                         mimeType: "image/jpeg")
                for (key, value) in parameters {
                    multipartFormData.append(value.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue))!, withName: key)
                }
        },
            to: completeUrl,
            headers: headers,
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON{ response in
                        print(response)
                    }
                case .failure(let encodingError):
                    print(encodingError)
                }
            }
        )

Postman Response Success on postman but having issue with headers, can you point out the silly mistake i have make


原文:https://stackoverflow.com/questions/42935529
更新时间:2022-05-31 12:05

最满意答案

有许多可能的算法加速。 一些基本的可能是:

  • 首先,如果你只对最大的素质因素感兴趣,你应该从最大的可能性中检查它们,而不是最小的。 因此,不要从2循环到a/2尝试 downto 2进行检查。
  • 您可以加载素数据库而不是使用isprime函数(网络中有几十个这样的文件)
  • 此外,只有奇数可以是素数( 2除外),因此您可以在每次迭代中“跳跃”2个值

您的isprime检查器也可以突出显示,您不必查找高达b/2 divisiors,只需检查sqrt(b) ,从而将复杂度从O(n)降低到O(sqrt(n)) (假设模运算是恒定时间)。


There are many possible algorithmic speed ups. Some basic ones might be:

  • First, if you are only interested in the largest prime factor, you should check for them from the largest possible ones, not smallest. So instead of looping from 2 to a/2 try to check from a downto 2.
  • You could load the database of primes instead of using isprime function (there are dozens of such files in the net)
  • Also, only odd numbers can be primes (except for 2) so you can "jump" 2 values in each iteration

Your isprime checker could also be speededup, you do not have to look for divisiors up to b/2, it is enough to check to sqrt(b), which reduces complexity from O(n) to O(sqrt(n)) (assuming that modulo operation is constant time).

相关问答

更多
  • 实际上,有几种更有效的方式来找出大数量的因素(对于较小的试验部门的工作相当好)。 如果输入数字具有非常接近于其平方根的两个因素,那么非常快的一种方法被称为费马因子分解 。 它利用身份N =(a + b)(a - b)= a ^ 2 - b ^ 2,易于理解和实现。 不幸的是,它一般不是很快。 二进制筛是最常用的将数字分配到100位数的方法。 作为一个奖励,算法的一部分很容易通过并行处理完成。 我听说过的另一种算法是Pollard的Rho算法 。 它并不像二次筛一般有效,但似乎更容易实现。 一旦你决定如何将一 ...
  • num = 600851475143; 这里发生整数溢出。 num的大小不足以包含您提供的值。 使用uint64_t 。 #include //must include this! uint64_t num = 600851475143; 阅读本文: cstdint num = 600851475143; Integer overflow occurs here. The size of num is not large enough to contain the value ...
  • 我真的没有得到你想要完成的东西。 就这么简单: def largestPrimeFactor(b : BigInt) = { def loop(f:BigInt, n: BigInt): BigInt = if (f == n) n else if (n % f == 0) loop(f, n / f) else loop(f + 1, n) loop (BigInt(2), b) } 虽然这里没有优化,但我立刻得到了结果。 唯一的“技巧”是你必须知道一个数字的最 ...
  • 当它真的被翻译成Prolog时,一个天真的强力搜索仍然是一个天真的强力搜索。 没关系:Plain Prolog非常适合描述和运行强力搜索。 不过,用Prolog编写的暴力搜索,你可能无法击败手动优化的任何蛮力搜索的低级版本。 另一方面,Prolog非常简单方便,你很可能很快就会找到更好的搜索策略,并且有一些原型,而这些其他策略通常会很容易地以巨大的优势击败任何暴力破解。 即使翻译得天真,Prolog在回溯方面也非常出色,并且在较低级代码的某些(更小或更大,取决于您使用的Prolog实现)因素中有效地执行。 ...
  • 数字600851475143超出了可以用PHP中的整数表示的范围,因此当您使用32位计算机时, 600851475143 / 6857不是整数: php> var_dump(600851475143/6857); float(87625999) 如果您使用BC任意精度库中的bcmod实现可分性检查,则可以使其工作: php> echo bcmod('600851475143','6857'); 0 在你的代码中: for ($i=$test; $i > 1 ; $i--) { if(bcmod ...
  • public static void main(String[] args) { int array[]= new int[100]; { int index=0; for(int i=0;i<100;i++) { int m; m=search(i); if(m==1||m==2 || m==3 || m==5){ array[index++]=i; } } }} 看看。我希望它会有所帮助。 public static void main(String[] args) { int array[ ...
  • 有许多可能的算法加速。 一些基本的可能是: 首先,如果你只对最大的素质因素感兴趣,你应该从最大的可能性中检查它们,而不是最小的。 因此,不要从2循环到a/2尝试从 downto 2进行检查。 您可以加载素数据库而不是使用isprime函数(网络中有几十个这样的文件) 此外,只有奇数可以是素数( 2除外),因此您可以在每次迭代中“跳跃”2个值 您的isprime检查器也可以突出显示,您不必查找高达b/2 divisiors,只需检查sqrt(b) ,从而将复杂度从O(n)降低到O(sqrt(n)) (假设模运 ...
  • 几乎和蛮力一样:计算一个md5sum是微不足道的,但是使一个文件匹配一个已知的md5sum是很困难的。 在最好的情况下,你正在寻找一个能够给你一个已知散列的预映像(可能通过将数据添加到二进制文件中)。 Pretty much the same as brute force: computing a md5sum is trivial, but making a file to match a known md5sum is hard. You are, in the best case, looking f ...
  • 每个数字都可以表示为: x = 1 p 1 .a 1 p 1 ... a n p n 哪里: a i 1 <= i <= n是素因子。 因此,为了使x尽可能最小,所有因子应为2 ,因此x将为2 ^ f(x) 。 x的除数是:(p 1 + 1)(p 2 + 1)...(p n + 1)所以你的附加条件也会得到满足! Every number can be represented in the form of: x = a1p1.a1p1...anpn Where: ai 1 <= i <= n are pri ...
  • n=600851475143 d=2 while d < n/d: if n%d==0: n/=d else: d+=1 print n n=600851475143 d=2 while d < n/d: if n%d==0: n/=d else: d+=1 print n

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)