Giter Club home page Giter Club logo

weex-nat-transfer's Introduction

nat-transfer

Installation

weexpack plugin add nat-transfer
npm install natjs --save

Usage

Use in weex project (.vue/.we)

<script>
import Nat from 'natjs'

Nat.download({
    url: 'http://domain.com/file'
})

Nat.upload({
    url: 'http://domain.com/upload',
    path: 'filepath'
})

</script>

See the Nat Documentation for more details.

weex-nat-transfer's People

Contributors

acathur avatar huangyakai avatar huangyake avatar jinzunmingyue avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

weex-nat-transfer's Issues

Request to add customizable form-data name

I think it would be nice to allow the Upload method to receive a custom name for the HTTP Form variable. Currently, I can't find a way to change the hard-coded name="file"

Example of actual request:
...Content-Disposition: form-data; name="file"; filename="IMG_20171231_185954.jpg"...

APIs and Forms already deployed, they might be expecting a different name there

upload 回调问题

default

文件上传时会有4次回调,最后一次才是需要的 result返回值,然而:
callback.invoke();//只回调一次 ,
多次回调必然需要用invokeAndKeepAlive();

add headers bug

2017-08-09 00 06 13

//headerValues 对象是新创建的 !=null
if (headerValues == null) { }//条件不成立

for (int i = 1; i < headerValues.size(); ++i) { connection.addRequestProperty();//不会执行添加header参数 }//headerValues.size == 0 条件不成立

Nat.upload not adding custom headers on Android

I'm trying to add a JWT for authorisation purposes but it's being ignored on Android, can't test this on IOS. Code is as follows, I'm also attaching the output of an echo server

	apiUpload(){
		if (!this.filePath) {
			Nat.toast('Please pick a file first :)')
			return
		}

		Nat.upload(this.url, {
			path: this.filePath,
			method: 'POST',
			formData: {
				framework: 'natjs',
			},
			headers: {
				'x-sign': 'customheader',
				'x-header': 'customheader',
				'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.SomeTokenValue',
			}
		}, {
			onProgress: (p) => {
				Nat.toast('Progressing: ' + p)
			}
		}, (err, res) => {
			if (err) {
				Nat.toast('[ERROR] ' + JSON.stringify(err))
				return
			}

			Nat.toast(JSON.stringify(res))
		})
	}

With something like this, the file is posted, the formData is posted but headers are not adding the custom ones, jut just add a series of apparently default headers such as User-Agent etc but not the custom ones in my code sample. See the output of a debug server:

[server] event: connection
[connection] event: data
--> POST / HTTP/1.1
--> Content-Type: multipart/form-data; boundary=3462-1016-3362-6531551161-5167-76-98-93
--> Transfer-Encoding: chunked
--> User-Agent: Dalvik/2.1.0 (Linux; U; Android 6.0; Android SDK built for x86 Build/MASTER)
--> Host: 10.0.2.2:7777
--> Connection: Keep-Alive
--> Accept-Encoding: gzip
-->
--> 4000
--> --3462-1016-3362-6531551161-5167-76-98-93
--> Content-Disposition: form-data; name="framework"
-->
--> natjs
--> --3462-1016-3362-6531551161-5167-76-98-93
--> Content-Disposition: form-data; name="file"; filename="IMG_20171231_185954.jpg"
--> Content-Type: image/jpeg
-->
--> ����JFIF��9dExifIIbj(2 REST OF BINARY DATA

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.