Esempio n. 1
0
    def post(self, request):
        super(ProjectFileDirectUploadView, self).post(request)

        key = get_upload_path(self.project.id_label,
                              self.form.cleaned_data['filename'])

        data_file = ProjectDataFile(
            user=self.project_member.member.user,
            file=key,
            metadata=self.form.cleaned_data['metadata'],
            direct_sharing_project=self.project)

        data_file.save()

        s3 = S3Connection(settings.AWS_ACCESS_KEY_ID,
                          settings.AWS_SECRET_ACCESS_KEY)

        url = s3.generate_url(
            expires_in=settings.INCOMPLETE_FILE_EXPIRATION_HOURS * 60 * 60,
            method='PUT',
            bucket=settings.AWS_STORAGE_BUCKET_NAME,
            key=key)

        return Response({
            'id': data_file.id,
            'url': url,
        },
                        status=status.HTTP_201_CREATED)
Esempio n. 2
0
    def post(self, request):
        super().post(request)

        key = get_upload_path(self.project.id_label, self.form.cleaned_data["filename"])

        datafile = ProjectDataFile(
            user=self.project_member.member.user,
            file=key,
            metadata=self.form.cleaned_data["metadata"],
            direct_sharing_project=self.project,
        )

        datafile.save()
        datafile.datatypes.set(self.form.cleaned_data["datatypes"])

        s3 = S3Connection(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)

        url = s3.generate_url(
            expires_in=settings.INCOMPLETE_FILE_EXPIRATION_HOURS * 60 * 60,
            method="PUT",
            bucket=settings.AWS_STORAGE_BUCKET_NAME,
            key=key,
        )

        return Response({"id": datafile.id, "url": url}, status=status.HTTP_201_CREATED)
Esempio n. 3
0
        continue

    try:
        data_file = DataFile.objects.get(file=key.key)
    except DataFile.DoesNotExist:
        print("Does not exist: {}".format(key.key))

        continue
    except DataFile.MultipleObjectsReturned:
        print("Multiple objects: {}".format(key.key))

        continue

    file_name = os.path.basename(key.key)

    new_key = get_upload_path(data_file, file_name)

    print(key.key)
    print("  {}".format(file_name))
    print("  {}".format(new_key))
    print("")

    s3.Object(BUCKET_NAME, new_key).copy_from(
        CopySource="{0}/{1}".format(BUCKET_NAME, key.key)
    )

    data_file.file = new_key
    data_file.save()

    key.delete()