laurilehmijoki / s3_website

Manage an S3 website: sync, deliver via CloudFront, benefit from advanced S3 website features.
Other
2.24k stars 186 forks source link

Fail to upload if path has Chinese #102

Closed zhuochun closed 10 years ago

zhuochun commented 10 years ago

When I try to upload paths that contain Chinese, it failed.

[fail] Failed to upload tags/逻辑/index.html ((SyntaxError) <script>:1: invalid multibyte char (US-ASCII))
laurilehmijoki commented 10 years ago

Hi and thanks for reporting the problem. I've just released the version 2.1.13, which has an improved error printer. Please upgrade into it and run s3_website push --verbose. The --verbose switch should print a more detailed error message. Then please paste the error message here, so that I can take a closer look at it.

The "invalid multibyte char" message suggests that there might be a problem in you _s3website.yml file. Can you paste its contents here? Remember to erase sensitive information such as credentials.

zhuochun commented 10 years ago

Using command s3_website push --dry-run --verbose, the error:

[fail] Failed to upload tags/笔记/index.html ((SyntaxError) <script>:1: invalid multibyte char (US-ASCII)
       s3.website.model.Upload$$anonfun$maxAge$1$$anonfun$apply$5$$anonfun$apply$6.apply(push.scala:84)
       s3.website.model.Upload$$anonfun$maxAge$1$$anonfun$apply$5$$anonfun$apply$6.apply(push.scala:83)
       scala.collection.IndexedSeqOptimized$$anonfun$1.apply(IndexedSeqOptimized.scala:50)
       scala.collection.IndexedSeqOptimized$$anonfun$1.apply(IndexedSeqOptimized.scala:50)
       scala.collection.IndexedSeqOptimized$class.segmentLength(IndexedSeqOptimized.scala:195)
       scala.collection.mutable.ArrayBuffer.segmentLength(ArrayBuffer.scala:48)
       scala.collection.GenSeqLike$class.prefixLength(GenSeqLike.scala:93)
       scala.collection.AbstractSeq.prefixLength(Seq.scala:41)
       scala.collection.IndexedSeqOptimized$class.find(IndexedSeqOptimized.scala:50)
       scala.collection.mutable.ArrayBuffer.find(ArrayBuffer.scala:48)
       s3.website.model.Upload$$anonfun$maxAge$1$$anonfun$apply$5.apply(push.scala:83)
       s3.website.model.Upload$$anonfun$maxAge$1$$anonfun$apply$5.apply(push.scala:82)
       scala.util.Either.fold(Either.scala:99)
       s3.website.model.Upload$$anonfun$maxAge$1.apply(push.scala:80)
       s3.website.model.Upload$$anonfun$maxAge$1.apply(push.scala:75)
       scala.Option.flatMap(Option.scala:170)
       s3.website.model.Upload.maxAge$lzycompute(push.scala:75)
       s3.website.model.Upload.maxAge(push.scala:73)
       s3.website.S3$$anonfun$toPutObjectRequest$1$$anonfun$apply$4$$anonfun$apply$5.apply(S3.scala:75)
       s3.website.S3$$anonfun$toPutObjectRequest$1$$anonfun$apply$4$$anonfun$apply$5.apply(S3.scala:69)
       scala.util.Success$$anonfun$map$1.apply(Try.scala:236)
       scala.util.Try$.apply(Try.scala:191)
       scala.util.Success.map(Try.scala:236)
       s3.website.S3$$anonfun$toPutObjectRequest$1$$anonfun$apply$4.apply(S3.scala:69)
       s3.website.S3$$anonfun$toPutObjectRequest$1$$anonfun$apply$4.apply(S3.scala:68)
       scala.util.Success.flatMap(Try.scala:230)
       s3.website.S3$$anonfun$toPutObjectRequest$1.apply(S3.scala:68)
       s3.website.S3$$anonfun$toPutObjectRequest$1.apply(S3.scala:66)
       scala.util.Either.fold(Either.scala:98)
       s3.website.S3$.toPutObjectRequest(S3.scala:65)
       s3.website.S3$$anonfun$uploadToS3$1.apply(S3.scala:32)
       s3.website.S3$$anonfun$uploadToS3$1.apply(S3.scala:31)
       scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
       scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24))

My s3_website.yml file:

max_age:
  "assets/*": 86400
  "*": 21600

gzip:
  - .html
  - .css
  - .js
  - .json
  - .txt
  - .xml

# See http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
# for valid endpoints
s3_endpoint: ap-southeast-1

# ignore_on_server: that_folder_of_stuff_i_dont_keep_locally

# exclude_from_upload:
#   - those_folders_of_stuff
#   - i_wouldnt_want_to_upload

# s3_reduced_redundancy: true

# cloudfront_distribution_id: your-dist-id

# cloudfront_distribution_config:
#   default_cache_behavior:
#     min_TTL: <%= 60 * 60 * 24 %>
#   aliases:
#     quantity: 1
#     items:
#       CNAME: your.website.com

# cloudfront_invalidate_root: true

# concurrency_level: 5

redirects:
  articles/category/software: /categories/software
  articles/category/blog: /categories/blog

routing_rules:
  - condition:
      key_prefix_equals: articles/tag/
    redirect:
      host_name: www.example.com
      replace_key_prefix_with: tags/
      http_redirect_code: 301
  - condition:
      key_prefix_equals: feed/
    redirect:
      host_name: www.example.com
      replace_key_prefix_with: feed.xml
      http_redirect_code: 301

Thanks.

laurilehmijoki commented 10 years ago

Thanks for the additional info. The version 2.1.15 contains the fix for this bug.

The commit is here: https://github.com/laurilehmijoki/s3_website/commit/898967db456bde4aac83153bbd214e2517e08a8a.

The solution was to instruct JRuby to use the UTF-8 encoding.

zhuochun commented 10 years ago

Thanks :100:

zhuochun commented 10 years ago

There is another error that cause an exception. Thanks.

Exception in thread "main" org.jruby.exceptions.RaiseException: (SyntaxError) <script>:2: invalid multibyte char (US-ASCII)
    at s3.website.Ruby$.rubyRegexMatches(Ruby.scala:7)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10$$anonfun$apply$7$$anonfun$apply$8.apply(Diff.scala:53)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10$$anonfun$apply$7$$anonfun$apply$8.apply(Diff.scala:53)
    at scala.collection.Iterator$class.exists(Iterator.scala:769)
    at scala.collection.AbstractIterator.exists(Iterator.scala:1174)
    at scala.collection.IterableLike$class.exists(IterableLike.scala:77)
    at scala.collection.AbstractIterable.exists(Iterable.scala:54)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10$$anonfun$apply$7.apply(Diff.scala:53)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10$$anonfun$apply$7.apply(Diff.scala:53)
    at scala.util.Either.fold(Either.scala:99)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10.apply(Diff.scala:51)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$10.apply(Diff.scala:51)
    at scala.Option.exists(Option.scala:228)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5.apply(Diff.scala:51)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4$$anonfun$apply$5.apply(Diff.scala:50)
    at scala.collection.TraversableLike$$anonfun$filterImpl$1.apply(TraversableLike.scala:259)
    at scala.collection.immutable.List.foreach(List.scala:383)
    at scala.collection.TraversableLike$class.filterImpl(TraversableLike.scala:258)
    at scala.collection.TraversableLike$class.filterNot(TraversableLike.scala:278)
    at scala.collection.AbstractTraversable.filterNot(Traversable.scala:104)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4.apply(Diff.scala:50)
    at s3.website.Diff$$anonfun$resolveDeletes$1$$anonfun$apply$4.apply(Diff.scala:47)
    at scala.util.Either$RightProjection.map(Either.scala:535)
    at s3.website.Diff$$anonfun$resolveDeletes$1.apply(Diff.scala:47)
    at s3.website.Diff$$anonfun$resolveDeletes$1.apply(Diff.scala:45)
    at scala.util.Success$$anonfun$map$1.apply(Try.scala:236)
    at scala.util.Try$.apply(Try.scala:191)
    at scala.util.Success.map(Try.scala:236)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
laurilehmijoki commented 10 years ago

Hi @zhuochun. Sorry! My bad. I didn't realise that I need to apply the same fix on the ignore_on_server config.

The version 2.1.16 contains a fix. Please try it and tell me how it works for you.

The commit is here:https://github.com/laurilehmijoki/s3_website/commit/208497b24323089705cd6553315bffbfaebbf0d4.

zhuochun commented 10 years ago

Works great :dancers: Thanks again