def sky_download(filen,skylink): try: Skynet.download_file(filen,upload_f.skylink) print("Downloaded!") except: print("Skylink does not exist or could not be generated.")
def main(): #coder A = encode() #upload image skylink = Skynet.upload_file(A) print("Upload successful, skylink: " + skylink) #download image Skynet.download_file("./dest.png", skylink) print("Download successful") # encoder Image print("Decoded word- " + decode("./dest.png"))
def test_upload_and_download_file(): """Test uploading and download a file.""" src_file = "./testdata/file1" skylink = 'testskylink' sialink = Skynet.uri_skynet_prefix() + skylink # upload a file responses.add(responses.POST, 'https://siasky.net/skynet/skyfile', json={'skylink': skylink}, status=200) print("Uploading file " + src_file) sialink2 = Skynet.upload_file(src_file) if sialink != sialink2: sys.exit("ERROR: expected returned sialink " + sialink + ", received " + sialink2) print("File upload successful, sialink: " + sialink2) body = responses.calls[0].request.body assert str(body).find('Content-Disposition: form-data; name="file"; \ filename="file1"') != -1 with open(src_file, 'r') as fd: contents = fd.read().strip() assert str(body).find(contents) != -1 # download a file responses.add(responses.GET, 'https://siasky.net/' + skylink, "test\n", status=200) dst_file = tempfile.NamedTemporaryFile().name print("Downloading to " + dst_file) Skynet.download_file(dst_file, skylink) if not filecmp.cmp(src_file, dst_file): sys.exit("ERROR: Downloaded file at " + dst_file + " did not equal uploaded file " + src_file) print("File download successful") assert len(responses.calls) == 2