Search code examples
pythoncurlfile-uploadbrowserstack

python upload file with curl


i'm trying to upload an apk to server the code i used to upload using curl is written like this:

curl -u "musername:mypass" -X POST "https://myurl/upload" -F "file=@D:\path\to\location.apk"

i tried to make a script using python with requests library like this:

response = requests.post(
            self.urlUpload,
            files={"file" : open(self.apkLocation, 'r')},
            auth=(self.BSUsername, self.BSToken)
        )

but it gives me errors:

{"error":"Malformed archive"}

anyone knows why this erros appeared?


Solution

  • Have you had a chance to try something like below?

    import requests
    
        files = {
            'file': ('/path/to/app/file/Application-debug.apk', open('/path/to/app/file/Application-debug.apk', 'rb')),
        }
        response = requests.post('https://api-cloud.browserstack.com/app-automate/upload', 
                    files=files, 
                    auth=('BSUsername ', 'BSToken'))
        print (response.text)#THE APP URL (bs://<hashed appid>) RETURNED IN THE RESPONSE OF THIE CALL
    

    Check the BrowserStack REST API doc here