Skip to content
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

BUG & FIX: Windows path bugfix for "Error: ... contains invalid WIN32 path characters." #390

Closed
philippdonabauer opened this issue Feb 13, 2019 · 6 comments · Fixed by #392

Comments

@philippdonabauer
Copy link

To bugfix "invalid WIN32 path characters" insert following code.

This error message is produced if you use the Amplify private storage put command to upload on s3erver on windows. The identity id contains an ":" so the path for the private upload is "private/region:identity_id/file" and windows does not allow special characters like ":", "<"...

At:

constructor(bucket, key, content, metadata) {
this.bucket = bucket;
this.key = key;
this.content = content;

after this.key= key; insert following code:

if(process.platform === "win32") {
      this.key = this.key.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
    }
@philippdonabauer
Copy link
Author

If you wan't i can create an pull request?

Also some changes in the Filesystem are required to work:

  copyObject(
    srcBucket,
    srcKey,
    destBucket,
    destKey,
    replacementMetadata,
    done
  ) {

    if(process.platform === "win32") {
      srcKey = srcKey.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
      destKey = destKey.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
    }

   getObject(bucket, key, options, done) {
    if (typeof options === "function") {
      done = options;
      options = undefined;
    }

    if(process.platform === "win32") {
      key = key.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
    }
  existsObject(bucket, key, done) {
    if(process.platform === "win32") {
      key = key.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
    }

storeMetadata(bucket, key, metadata, md5, done) {
    if (typeof md5 === "function") {
      done = md5;
      md5 = null;
    }
    
    if(process.platform === "win32") {
      key = key.replace(/[<>:"|?*]/g, function (match, capture) {
        return  "%" + Buffer.from(match, 'utf8').toString("hex");
      });
    }
    deleteObject(bucket, key, done) {
    key = key.replace(/[<>:"|?*]/g, function (match, capture) {
      return  "%" + Buffer.from(match, 'utf8').toString("hex");
    });
  putObjectMultipart(bucket, key, uploadId, parts, metadata, done) {

    key = key.replace(/[<>:"|?*]/g, function (match, capture) {
      return  "%" + Buffer.from(match, 'utf8').toString("hex");
    });

@philippdonabauer philippdonabauer changed the title Windows path bugfix for "Error: ... contains invalid WIN32 path characters." BUG & FIX: Windows path bugfix for "Error: ... contains invalid WIN32 path characters." Feb 14, 2019
@leontastic
Copy link
Collaborator

@philippdonabauer We'd be happy to have your PR. Can you write a test in https://github.com/jamhall/s3rver/blob/master/test/test.js with your use case that fails on Windows, then PR your test code and post your output?

@kherock kherock mentioned this issue Feb 18, 2019
24 tasks
@philippdonabauer
Copy link
Author

@leontastic yes i can do. Next weekend i will write a test and make a pull request with the depending changes. Thank you.

@SimonLegg
Copy link

SimonLegg commented Dec 31, 2019

Still getting this error --version 4.5.0

await Strorage.vault.put(fileName, file);

develop\private\eu-west-1:676aefb9-b94e-4a93-ba85-ad e35ef2d202 contains invalid WIN32 path characters.

It might be that the test created in relation to #420 with commit cf29c53 doesn't consider region or amplify mock (just guesses as don't have time to look into currently)

Workaround: use public (not vault or level: private)

Note: potentially region was not in path before, region is not in public as yet

@rehanbabertkxel
Copy link

@SimonLegg , yes. I am facing the same issue. But I need to use protected or private. Any workaround for it?

@SimonLegg
Copy link

@rehanbabertkxel - I'm just in development at the moment so I'm sticking with public until i need to properly deploy then I'll just switch to private. I might use project environment variables or build environment to still allow amplify mock to be used for local development.

Regards

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

Successfully merging a pull request may close this issue.

4 participants