share api 문의
데일리프로그랭
3년 전
조회 2,158
share api를 통해 이미지를 공유하고 싶습니다.
2.0부터 파일쉐어가 가능한것으로 알고있으며, 해당경우 업로드되는 파일 쉐어로 이미지를 파일 형태로 변경해서 공유하는 기능을 구현중입니다.
Blob 형태로 구현중인데 잘 동작하지 않네요. 아래 코드에서 file, blob 출력시 true로 출력하며, 실제 이미지주소로 이미지는 이상없는것으로 확인했습니다.
문제는 Blob으로 변경된 이미지가 공유시 제대로 노출되지 않습니다. 파일은 있으나 이미지가 깨진(?) 제대로 노출되지 않는 형태로 보아 변환에 문제가 있는것 같은데 도움을 요청드립니다.
</p>
<p><script></p>
<p> img_url = $(".img").attr("src");</p>
<p> let img_file = img_to_blob(img_url );</p>
<p> var blob = new Blob(["This is the sample data"],</p>
<p> {type : "image/jpeg"});</p>
<p> const file = new File([blob], imgUrl, {</p>
<p> type: blob.type,</p>
<p> });</p>
<p> </p>
<p> console.log(file instanceof File); //true</p>
<p> console.log(file instanceof Blob); //true</p>
<p> console.log(file); </p>
<p> </p>
<p> let filesArray = [];</p>
<p> filesArray.push(file);</p>
<p> </p>
<p> if (navigator.canShare && navigator.canShare({ files: filesArray })) {</p>
<p> var webUrl = location.protocol+"<?php echo '//'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>";</p>
<p> </p>
<p> navigator.share({</p>
<p> files: filesArray,</p>
<p> title: "<?php echo str_replace(array('%27', '"' , '\"'), '', strip_tags($view['subject'])); ?>",</p>
<p> text: "<?php echo preg_replace('/\r\n|\r|\n/','', strip_tags(get_text(cut_str(strip_tags($view['content']), 200), 1))); ?>",</p>
<p> url: webUrl,</p>
<p> })</p>
<p> .then(() => console.log('Share Success'))</p>
<p> .catch((error) => console.log('Share Fail', error));</p>
<p> }else{</p>
<p> alert('Share API is not working');</p>
<p> }</p>
<p></script></p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
답변을 작성하려면 로그인이 필요합니다.
로그인