React Native 代码片段
来源:互联网 发布:平安普惠网络异常 编辑:程序博客网 时间:2024/05/26 09:57
一. Upload Image – fetch
alvaromb - 2015年9月28日
export function postData (url, params, fileURL) { let data = new FormData() if (fileURL) { data.append('image', {uri: fileURL, name: 'image.jpg', type: 'image/jpg'}) } _.each(params, (value, key) => { if (value instanceof Date) { data.append(key, value.toISOString()) } else { data.append(key, String(value)) } }) const config = { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'multipart/form-data; boundary=6ff46e0b6b5148d984f148b6542e5a5d', 'Content-Language': React.NativeModules.RNI18n.locale, 'Authorization': 'Token ABCDEF123457890', }, body: data, } return fetch(API_URL + url, config) .then(checkStatusAndGetJSONResponse)}
sorenbs - 2015年8月13日
var options = { title: 'Upload image', cancelButtonTitle: 'Cancel', takePhotoButtonTitle: 'Take Photo...', chooseFromLibraryButtonTitle: 'Choose from Library...', returnBase64Image: true, returnIsVertical: false };UIImagePickerManager.showImagePicker(options, (type, response) => { if (type !== 'cancel') { var source; if (type === 'data') { source = {uri: 'data:image/jpeg;base64,' + response, isStatic: true}; } else { source = {uri: response}; } console.log("uploading image"); fetch('server-endpoint',{ method: 'post', body: "data=" + encodeURIComponent(source.uri) }).then(response => { console.log("image uploaded") console.log(response) }).catch(console.log); //this.setState({avatarSource:source}); } else { console.log('Cancel'); } });
0 0
- React Native 代码片段
- react-native 代码片段
- React Native 代码规范
- [React-Native]初识代码结构
- React Native 的代码规范
- React Native跨平台代码说明
- React-Native代码自动提示(WebStorm)
- React-Native编写针对平台的代码
- 原生代码中接入React Native
- React Native跨平台代码说明
- react native 混合开发代码示例
- React Native 数据库链接测试代码
- react-native-art path代码解析
- react-native 代码编程规范、约定
- react-native-quan代码分析笔记
- react native
- React Native
- React Native
- IOS开发笔记 - 基于SDWebImage的网络图片加载处理
- Redis升级高版本报错解决方法
- 如何批量kill进程
- oracle中插入数据出现错误:ORA-02291: 违反完整约束条件 (SCOTT.FK_SX9MLJB8T3FWB40GVCSKHYSYT)- 未找到父项关键字
- kubenetes无法创建pod/创建RC时无法自动创建pod的问题
- React Native 代码片段
- 用java比较两个集合对象中不一样的元素。
- 柴俊理金:油价美股支撑风险,避险黄金遭受打压
- 文章标题
- LeetCode 339. Nested List Weight Sum
- mysql的一些注意的
- MySQL事务管理+安全管理+MySQL数据类型
- 二叉树的深度和平衡二叉树
- 屏幕触摸