te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - (React-Native) undefined is not a constructor evaluating 'new FormData()' - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - (React-Native) undefined is not a constructor evaluating 'new FormData()' - Stack Overflow

programmeradmin4浏览0评论

for the past 2 days I struggled with this problem and can't figure it out. I don't understand this error. this is my code:

try{
var formData = new FormData();
} catch (error) {
console.error('FormData ERROR', error);
}

and this is the error:

017-06-21 13:49:02.761 [error][tid:.facebook.React.JavaScript] 'FormData ERROR', { [TypeError: undefined is not a constructor (evaluating 'new FormData()')] line: 98419, column: 36, sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false' }

Do i have to add support for FormData in ReactNative 0.45.0? please help

for the past 2 days I struggled with this problem and can't figure it out. I don't understand this error. this is my code:

try{
var formData = new FormData();
} catch (error) {
console.error('FormData ERROR', error);
}

and this is the error:

017-06-21 13:49:02.761 [error][tid:.facebook.React.JavaScript] 'FormData ERROR', { [TypeError: undefined is not a constructor (evaluating 'new FormData()')] line: 98419, column: 36, sourceURL: 'http://localhost:8081/index.ios.bundle?platform=ios&dev=true&minify=false' }

Do i have to add support for FormData in ReactNative 0.45.0? please help

Share Improve this question edited Mar 5, 2018 at 12:45 David Schumann 14.8k13 gold badges83 silver badges105 bronze badges asked Jun 21, 2017 at 11:03 Cristi MileaCristi Milea 911 gold badge2 silver badges7 bronze badges 4
  • FormData is undefined, can you make sure that the object exists in your code? – Mμ. Commented Jun 21, 2017 at 11:47
  • @D-reaper how do i do that? FormData i think is included in react-native / libraries / network – Cristi Milea Commented Jun 21, 2017 at 12:30
  • console.log(FormData). If it is undefined, then you just have to make sure that you include it in your code. – Mμ. Commented Jun 21, 2017 at 12:31
  • after console.log(FormData) i get undefined. i tried import { FormData } from 'react-native'; but still no luck – Cristi Milea Commented Jun 21, 2017 at 12:47
Add a ment  | 

4 Answers 4

Reset to default 5

I got into this problem as well and that's because I have imported them on top. If you have done like what I did:

import { FormData } from 'react';

or

import { FormData } from 'react-native';

Just remove "FormData" from your imports and it will work like magic. FormData doesn't have to be imported for it to be working.

The error says that you are FormData is undefined. Since it is not part of react native, you probably have to download it from npm.

npm install --save form-data

Then import it at the top of your file

import FormData from 'form-data';

if

import { FormData } from 'react-native';

didn't help then you can try to import directly:

import FormData from 'react-native/Libraries/Network/FormData';

I think I got it.

First of all, I found something (don't know from where i had these "tips") in my index.ios.js and removed them

// const _XHR = GLOBAL.originalXMLHttpRequest ?  
//     GLOBAL.originalXMLHttpRequest :           
//     GLOBAL.XMLHttpRequest                     

// XMLHttpRequest = _XHR;

// // FormData = global.originalFormData;

Then I found out that my debugger (Chrome or RNDebugger) messed with my network requests and that was bad for multipart image object. (strange?!)

finally i got it working with this code:

var fdObject = new FormData();
fdObject.append('avatar', {uri: PicturePath, name: 'avatar.jpg', type: 'image/jpg'});
options.method = POST;
options.headers['Content-Type'] = 'multipart/form-data';
options.body = fdObject;
fetch("http://api./post-my-image", options);
发布评论

评论列表(0)

  1. 暂无评论