Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 재귀함수
- ReactNative
- react-native
- 페이지리렌더링
- fcm push
- 알고리즘
- asyncstorage
- 리액트
- 리액트 네이티브
- 자동로그인
- modal
- 2023년 정처기 필기
- C++98에러
- fcm 푸시
- 모달
- 모달에서뒤로가기
- vision-camera
- 순열
- API
- 가격자릿수
- React
- Icon
- makePermutation
- 리액트네이티브
- algorithm
- JSON
- touchableopacity
- TextInput
- 뒤로가기구현
- Flatlist
Archives
- Today
- Total
생각은 길게 코딩은 짧게
[React-Native] Image Blob 본문
728x90
API를 사용하여 사업자 등록증과 명함 사진을 서버에서 들고와보았습니다.
✅ 로그인 되어있는 사용자의 아이디와 패스워드를 서버로 보내 사진을 가져오는 API
//사업자등록증 사진을 가져오는 API
async callGetCompanyImage(loginInfo) {
let manager = new WebServiceManager(Constant.serviceURL + "/GetCompanyImage", "post");
manager.addFormData("data", {
userID: loginInfo.userID, passwd: loginInfo.passwd, id: 2
});
let response = await manager.start();
if (response.ok) {
return response.blob();
}
}
//명함 사진을 가져오는 API
async callGetcardImage(loginInfo) {
let manager = new WebServiceManager(Constant.serviceURL + "/GetNamecardImage", "post");
manager.addFormData("data", {
userID: loginInfo.userID, passwd: loginInfo.passwd, id: 2
});
let response = await manager.start();
if (response.ok) {
return response.blob();
}
}
return response.blob(); 을 통해 회원가입 시 등록하였던 사업자등록증 & 명함 사진을 가져올 수 있습니다.
✅ 정보 수정 페이지에 접근하자마자 호출될 수 있도록 componentDidMount에서 API를 호출
componentDidMount() {
this.getLoginInfo().then((value) => {
this.loginInfo.companyNo=value.companyNo;
this.loginInfo.userID = value.id;
this.loginInfo.passwd = value.passwd;
this.setState({ companyNo: value.companyNo ,value:value})
console.log(this.state.companyNo)
this.callGetCompanyImage(this.loginInfo).then((response) => {
let reader = new FileReader();
reader.readAsDataURL(response);
reader.onloadend = () => {
this.setState({ companyNoImageURL: reader.result });
}
});
this.callGetcardImage(this.loginInfo).then((response) => {
let reader = new FileReader();
reader.readAsDataURL(response);
reader.onloadend = () => {
this.setState({ cardImageURL: reader.result });
}
});
});
}
로그인 되어있는 사용자의 정보를 AsyncStorage에서 받아와 API를 실행해주었다
✅ render()
<View style={styles.imageRegister_btnLayout_view}>
{/*사업자 등록증 사진*/}
<View style={styles.imageRegister_btn_view}>
<Text style={[styles.default_text, styles.imageRegister_title_text]}>사업자 등록증</Text>
<TouchableOpacity style={styles.imageRegister_btn} onPress={this.companyImageModal}>
<Image source={{ uri: this.state.companyNoImageURL }} style={styles.imageRegister_image_view} />
</TouchableOpacity>
</View>
{/*명함 사진*/}
<View style={styles.imageRegister_btn_view}>
<Text style={[styles.default_text, styles.imageRegister_title_text]}>명함</Text>
<View onLayout={(event) => { this.getViewSize(event) }} ref={this.photoCameraIcon}>
{this.state.cardImageURL == "" ?
(<TouchableOpacity style={styles.imageRegister_btn} onPress={() => this.setState({ cardPopupMenuVisible: true })}>
<IconCamera name="image-inverted" size={60}></IconCamera>
</TouchableOpacity>) : (<TouchableOpacity style={styles.imageRegister_btn} onPress={this.cardImageModal}>
<Image source={{ uri: this.state.cardImageURL }} style={styles.imageRegister_image_view} />
<TouchableOpacity style={styles.imageDelete_btn} onPress={this.photoRemoveClicked}>
<IconDelete name="close-circle" color="black" size={27}></IconDelete>
</TouchableOpacity>
</TouchableOpacity>)
}
</View>
</View>
</View>
사업자 등록 이미지는 수정이 불가하고 명함 사진은 수정이 가능하도록 구현하였습니다.
'React Native' 카테고리의 다른 글
[React-Native] 전역 함수 사용하기 (0) | 2023.03.29 |
---|---|
[React-Native] 뒤로가기 구현 ( BackHandler ) (0) | 2023.03.20 |
[React-Native] 페이지 이동 시 자동 새로고침 (0) | 2023.03.03 |
[React-Native] 우편번호 찾기 API (0) | 2023.02.08 |
[React-Native] 찜하기 구현 (0) | 2023.02.07 |