예제 #1
0
    def qt_upload(archive, **options):
        from PyQt4 import QtNetwork, QtCore

        def part_parameter(key, value):
            part = QtNetwork.QHttpPart()
            part.setHeader(QtNetwork.QNetworkRequest.ContentDispositionHeader,
                           "form-data; name=\"%s\"" % (key))
            part.setBody(value)
            return part

        multiPart = QtNetwork.QHttpMultiPart(
            QtNetwork.QHttpMultiPart.FormDataType)
        multiPart.append(
            part_parameter("name",
                           options.get('name', '').decode('utf8')))
        multiPart.append(
            part_parameter("description",
                           options.get('description', '').decode('utf8')))
        multiPart.append(
            part_parameter("tags",
                           options.get('tags', 'KSP').decode('utf8')))
        multiPart.append(
            part_parameter("token",
                           options.get('token', '').decode('utf8')))
        multiPart.append(part_parameter("source", "ksp-exporter"))

        modelPart = QtNetwork.QHttpPart()
        modelPart.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                            "application/octet-stream")
        modelPart.setHeader(
            QtNetwork.QNetworkRequest.ContentDispositionHeader,
            "form-data; name=\"modelFile\"; filename=\"%s\"" % (archive))
        data = QtCore.QFile(archive)
        data.open(QtCore.QIODevice.ReadOnly)
        modelPart.setBodyDevice(data)
        data.setParent(multiPart)
        multiPart.append(modelPart)

        url = QtCore.QUrl(SKETCHFAB_API_URL)
        request = QtNetwork.QNetworkRequest(url)
        manager = QtNetwork.QNetworkAccessManager()
        reply = manager.post(request, multiPart)
        multiPart.setParent(reply)

        return (manager, reply)
예제 #2
0
def upload(fileModel, token, description, title, tags="minecraft"):
    from PyQt4 import QtNetwork, QtCore

    def part_parameter(key, value):
        part = QtNetwork.QHttpPart()
        part.setHeader(QtNetwork.QNetworkRequest.ContentDispositionHeader,
                       "form-data; name=\"%s\"" % (key))
        part.setBody(value)
        return part

    source = "minecraft-plugin"
    multiPart = QtNetwork.QHttpMultiPart(QtNetwork.QHttpMultiPart.FormDataType)
    multiPart.append(part_parameter("title", title))
    multiPart.append(part_parameter("description", description))
    multiPart.append(part_parameter("tags", tags))
    multiPart.append(part_parameter("token", token))
    multiPart.append(part_parameter("source", source))

    modelPart = QtNetwork.QHttpPart()
    modelPart.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader,
                        "application/octet-stream")
    modelPart.setHeader(
        QtNetwork.QNetworkRequest.ContentDispositionHeader,
        "form-data; name=\"fileModel\"; filename=\"%s\"" % (fileModel))
    file = QtCore.QFile(fileModel)
    file.open(QtCore.QIODevice.ReadOnly)
    modelPart.setBodyDevice(file)
    file.setParent(multiPart)
    multiPart.append(modelPart)

    url = QtCore.QUrl("%s/v1/models" % (sketchfab_url))

    request = QtNetwork.QNetworkRequest(url)

    manager = QtNetwork.QNetworkAccessManager()
    reply = manager.post(request, multiPart)
    multiPart.setParent(reply)

    return (manager, reply)
예제 #3
0
 def part_parameter(key, value):
     part = QtNetwork.QHttpPart()
     part.setHeader(QtNetwork.QNetworkRequest.ContentDispositionHeader,
                    "form-data; name=\"%s\"" % (key))
     part.setBody(value)
     return part