Sending large zip files to Django/Tastypie server

39 views Asked by At

I want to send some zip files from a raspberry Pi to my windows server. The zips are about 2GB each.

I'm using python sockets to send them.

def sendFile():
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    print('Socket created')
    s.connect(("http://192.168.0.21:8000/api/v1/ziptest/", 8000))
    print("Connected")
    for x in range(len(zipTypes)):
        filename = '/logs/rel_5_0608.3800_val2/{}.zip'.format(zipTypes[x])
        print("filename {} ".format(filename))
        with open(filename,'rb') as infile:
            d = infile.read(1024)
            while d:
                s.send(d)
                d = infile.read(1024)
    infile.close()

I've then got my resource function:

class ResponseZipTest(ModelResource):

    class Meta:
        limit = 100000
        queryset = TestZipModel.objects.all()
        resource_name = "ziptest"
        authorization = Authorization()
        always_return_data = True

    # Hydration function
    def hydrate(self, bundle):
        print("Server is ready to receive")

    def dehydrate(self, bundle):
        return bundle

When I run sendTest() I get Name or service not known but I can use curl on that URL just fine. My resource function never gets triggered.

My url file:

v1_api = Api(api_name='v1')
v1_api.register(ResponseZipTest())

test_model = ResponseZipTest()

urlpatterns = [
    url(r'^api/', include('api.urls')),
    url(r'^api/', include(v1_api.urls)),
    url(r'^api/', include(test_model.urls))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Are sockets the best way to send these files? Is there another method that'll simplify this?

0

There are 0 answers