Skip to content

Incorrect s3 upload path separator on windows #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AbsoluteDestiny opened this issue Feb 25, 2019 · 4 comments
Closed

Incorrect s3 upload path separator on windows #93

AbsoluteDestiny opened this issue Feb 25, 2019 · 4 comments
Assignees
Labels

Comments

@AbsoluteDestiny
Copy link

When django is being hosted on a windows machine (such as a local dev environment) the file is uploaded using backslashes as the path separator. So, instead of uploading to the /tmp/s3file folder the file get a single long filename with backslashes in it.

This then causes a File Does Not Exist IOError in boto3 when it tries to pull the file back.

@codingjoe codingjoe self-assigned this Feb 26, 2019
@codingjoe codingjoe added the bug label Feb 26, 2019
@codingjoe
Copy link
Owner

Hi @AbsoluteDestiny that's interesting. To be honest, I haven't tried the package on Windows yet. Do you happen to have a stacktrace for me or some sample code to reproduce this?

@codingjoe
Copy link
Owner

codingjoe commented Feb 26, 2019

@AbsoluteDestiny I think I found the bug and wrote a patch, can you test it please?
#94

@AbsoluteDestiny
Copy link
Author

AbsoluteDestiny commented Feb 26, 2019

@codingjoe I'm getting the following error:

'PurePosixPath' object has no attribute 'endswith'

in botocore\signers.py in generate_presigned_post

the boto code wants to do this:

    # Append that the bucket name to the list of conditions.
    conditions.append({'bucket': bucket})
    # If the key ends with filename, the only constraint that can be
    # imposed is if it starts with the specified prefix.
    if key.endswith('${filename}'): ...
        conditions.append(["starts-with", '$key', key[:-len('${filename}')]])
    else:
        conditions.append({'key': key})
    # Add the key to the fields.
    fields['key'] = key

on line 32 of your forms.py:

        response = self.client.generate_presigned_post(
            self.bucket_name, pathlib.PurePosixPath(self.upload_folder, '${filename}'),
            Conditions=self.get_conditions(accept),
            ExpiresIn=self.expires, ...
        )

looks like pathlib.PurePosixPath(self.upload_folder, '${filename}').as_posix() would give you the str boto expects.

@codingjoe
Copy link
Owner

thx @AbsoluteDestiny I just updated the PR, it should work now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants