Comments (1)
First some context: There are currently two methods in the $network
class: $network.request
and $network.upload
. Also, I am using the AFNetworking library to handle all network requests.
As you know, $network.request
covers a lot of basic needs but doesn't cover all the detailed features that AFNetworking (or NSURLRequest) supports yet. So this definitely needs to be done.
How $network.upload works
Anyway, after I wrote $network.request
I wanted an easy way to upload file to s3. But the problem with uploading to s3 is that it's not as straightforward as just uploading to your own server. You need to jump through all their security related hurdles to get the URL which you can post to. And this URL expires after a while. So I wrote a method called $network.upload
that simplifies that.
Basically $network.upload
takes your S3 bucket and path info and makes a GET
request to your server endpoint (sign_url
) which will then make a request to S3 from the backend to acquire a signed url, and then return it, and only then it uploads the content to the returned signed url. All this is encapsulated in this single method called $network.upload
.
About this issue
Now, coming back to this current feature--uploading raw data. I think this was one of the most important features missing from the $network.request
method. And I think think this is something $network.request
should implement instead of $network.upload
, for the reasons I mentioned above.
Normal upload vs. multipart upload
Although it would be cool to have multipart upload, upon investigating further, I don't think we have to go that far just yet. Instead we can take small steps and basically use the same code @makevoid wrote, but just need to integrate it into the right place (inside the JasonNetworkAction.request
method). In this case, just being able to upload raw data is very useful so it's definitely worth the effort.
Possible solutions
As for the markup, instead of:
{
"type":"$network.upload",
"options":{
"url":"https://localhost:3000/ipfs_add",
"method":"post",
"content_type":"image/jpeg",
"data":"{{$jason.data}}"
},
"success":{
"type":"$render"
}
}
I think we could do something like
{
"type":"$network.request",
"options":{
"url":"https://localhost:3000/ipfs_add",
"method":"post",
"content_type":"image/jpeg",
"data":"{{$jason.data}}",
"raw": "true"
},
"success":{
"type":"$render"
}
}
Notice the only difference is the action type $network.request
and the "raw": "true"
attribute. This would indicate that the data is posted as a raw data instead of being serialized into a form.
We could come up with a better name if anyone has a suggestion (For example jQuery uses processData: false
to express this condition).
Actual implementation
As for the actual implementation, I think we could take @makevoid's same code, and move it into the JasonNetworkAction.request
method and paste it for every case (GET
, POST
, PUT
, DELETE
) and wrap it with conditionals. For example for POST
I can imagine something like this:
if(method){
if([[method lowercaseString] isEqualToString:@"post"]){
if(self.options[@"raw"]){
// The upload code by @makevoid
} else {
// The existing POST code
}
}
}
This is safe since it doesn't affect the existing logic. As long as nobody uses the raw
attribute it would be fine.
Extra credit
This in itself is a great improvement, but we could also go further and actually refactor out the entire request
method, which I've been meaning to do for a while. If you look into AFNetworking source, the [manager POST: ...]
is nothing more than a wrapper around the dataTaskWithRequest: used in the upload code
Which means we could consolidate everything into a single dataTaskWithRequest:
method and shrink the entire request method itself down to like 20% of what it is now by using the source method.
This is a bit risky since we're basically overhauling the entire request method. We may split this out into another pull request, or I could do it myself.
Conclusion
- If anyone has a suggestion on how we should express this condition in JSON, please do so. (I've suggested
"offline": "true"
above). - @makevoid would you like to take a stab at making the change described above and send a pull request?
from jasonette-ios.
Related Issues (20)
- (low priority) shouldn't body.header not scroll with the sections? HOT 1
- href as action does not carry over parameters HOT 7
- href deep linking does not surpport options parameter HOT 1
- Add SMS action HOT 1
- Security Guidelines
- Android version not handling background style correctly
- Orientation change does not resize the web view for background web container HOT 1
- $href action - request for error callback HOT 2
- State not retained with $href in a webview with native transition HOT 2
- How can i add my own custom tags like head , body in jasonette? HOT 1
- POSTing body
- js alerts on webview are silently ignored HOT 1
- how to config default is load my homepage
- Development Moved to https://github.com/jasonelle/jasonelle HOT 2
- back button is not working HOT 1
- Extending • Swift-class component returns nil HOT 6
- NSInternalInconsistencyException with iOS13 HOT 1
- Showing image until web container is ready
- Bottom Tab Bar Issue
- Webcontainer back to start terminates app
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jasonette-ios.