如何将图像上传到swift3中的amazon存储桶?

时间:2017-01-19 07:22:57

标签: ios node.js swift3

我想将客户签名图像发布到带有api的amazon s3 bucket_type服务器...我指的是不同的教程...我没有从任何教程中获得足够的信息...我正在尝试跟随代码,但我得到零结果......

import turtle
import random
import itertools

COLORS = ['red', 'blue', 'green', 'yellow', 'black', 'pink', 'gold', 'violet', 'orange', 'magenta', 'cyan']

def random_color(iterator=[]):  # intentional dangerous default value
    if not iterator:  # empty container
        colors = COLORS
        random.shuffle(colors)
        iterator.append(itertools.cycle(colors))

    return next(iterator[0])

def square(length, x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()

    while length >= 10:
        color = random_color()  # change color after each square
        turtle.color(color)

        turtle.begin_fill()

        for _ in range(4):
            turtle.forward(length)
            turtle.right(90)

        turtle.end_fill()

        length -= 10

square(200, -100, 100)

turtle.done()

请任何人帮我解决此问题。 提前致谢。

1 个答案:

答案 0 :(得分:0)

  1. let urlpath:String = "http:myurl" + service看起来像是一个错字。
  2. 我假设服务变量包含一个带有可以上传到的预签名凭据的URL。确保这是正确的。如果不是,您必须让服务器为您提供预先签名的凭据。
  3. 使用PUT而非POST
  4. 我希望请求的主体只是imageData,但你似乎在向body中添加了很多东西。我不知道你要上传什么类型的文件,但你正在制作一个奇怪的文件。如果这是你的意图很好,但只是我们意识到你正在做的事情。如果缩进以上传自定义文件类型,我会将所有代码移动到另一个函数,然后使用另一个只上传数据的函数。
  5. 您必须设置的唯一HTTPHeader字段为Content-Length。必须将其设置为您发送的正文的大小。
  6. 请求的预期结果是长度为0且没有错误的数据。所以你的响应块中的JSONSerialization出错了。