1

I'm now trying my app in testing environment, and the app have a feature that open a URL in a webview, but now testing, the files URL in production database come from Amazon and have this format:

self.url = @"https://media.akdemia.com.s3.amazonaws.com/production//uploads/report_notification/report/3827/Corte_de_Notas_de-QUINTO_A_O_DE_CIENCIAS_A.pdf?AWSAccessKeyId=AKIAI2R6DMWPFKJPDVWQ&Signature=wwq2kCTVsOlA/Sc/xIT108XF8/0%3D&Expires=1447112397" 

I can't open it by:

NSURL *myUrl = [NSURL URLWithString:self.url];
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];

[self.webView loadRequest:myRequest];

Isn't a common url and the console print this error:

NSURLConnection/CFURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)

Extra info

In my app I have a reports list, and when it request to API the URL of each report, it generates a URLs list.

If I request that URLs from console is generate the same URL but distinct Expires numbers for each URL and all of this URL works correctly, while if I print the JSON that API returns for the app I can see that all the URLs (no matter which report belongs) have the same Expires number. I don't know if this can affect the URL and then it no works.

halfer
  • 18,701
  • 13
  • 79
  • 158
origds
  • 1,077
  • 2
  • 11
  • 25
  • 1
    I have just pasted your url in browser, due to fire wall it shows me privacy error to load this kind of url. Check that you have a permissions to load this url. Also make sure url is correct and it is able to load in simulator/device's Safari app. – Kampai Nov 10 '14 at 06:18
  • I have not been able to change it now, even when I do I write again @Kampai – origds Nov 10 '14 at 12:13
  • Not able to get your point, Can you please explain in details? – Kampai Nov 10 '14 at 12:15
  • I have to check the URL and if I have the permissions, but I can't just right now. When I do that Im gonna write you about your comment, thanks @Kampai – origds Nov 10 '14 at 12:18
  • Ok. Drop a comment after you have permission and still face an issue. – Kampai Nov 10 '14 at 12:20
  • @pbasdf this my other question – origds Nov 10 '14 at 12:29
  • Please read edited question @Kampai – origds Nov 10 '14 at 22:43
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/64675/discussion-between-kampai-and-origds). – Kampai Nov 11 '14 at 05:56
  • 1
    I'm not sure if it's the `expires` token that is causing the problem. I see from [this post](http://stackoverflow.com/a/6164117/3985749) that there is a problem with Amazon S3 for "buckets" with '.'s in them. One solution offered there is to restructure the URL slightly: so `https://media.akdemia.com.s3.amazonaws.com/production/....` becomes `https://s3.amazonaws.com/media.akdemia.com/production/....`. If I make that change, then I get past the 9843 error. But then get a document not found error (maybe because it's expired?). – pbasdf Nov 11 '14 at 10:43
  • Thank you guys pbasdf and @Kampai – origds Nov 12 '14 at 01:26

1 Answers1

2

I resolved the issue, I'm using Ruby on Rails for API implementation, and I changed fog and carrierwave gem version to 1.9.0 and 0.10.0 on the Gemfile (you have to run bundle install to update).

Using the same fog_credentials

config.fog_credentials = {
      :provider               => 'AWS',       # required
      :aws_access_key_id      => 'AKIAI2R6DMWPFKJPDVWQ',       # required
      :aws_secret_access_key  => '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',       # required
}
    config.fog_directory  = 'media.akdemia.com'                     # required
    config.fog_public     = false
    config.cache_dir = "#{Rails.root}/tmp/uploads"
    config.fog_authenticated_url_expiration = 1.year
    config.storage = :fog

And then the API generates URLs correctly https://s3.amazonaws.com/media.akdemia.com/production/.... instead of https://media.akdemia.com.s3.amazonaws.com/production/....

Thanks guys @Kampai and @pbasdf you were helpful to find the solution

origds
  • 1,077
  • 2
  • 11
  • 25