# Uploading image in database via Corvid

**URL:** <https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [September 4, 2020, 10:52pm UTC](https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484 "2020-09-04T22:52:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ademontis](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ademontis/32/23012_2.png) [@ademontis](https://forum.wixstudio.com/u/ademontis)\
**Post date:** [September 4, 2020, 10:52pm UTC](https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484/1 "2020-09-04T22:52:25Z")

</div>

Hi all,  
I’ve been trying to create a “Post new entry” lightbox that enables the user to create a new post to the website wall…  
my code is:

```javascript
export function button2_click(event) {
 let toInsert = {
postCreatorId: $w('#dataset2').getCurrentItem()._id,
postCreatorImage: $w('#dataset2').getCurrentItem().profileImage,
postCreator: $w('#dataset2').getCurrentItem().fullName,  
post: $w('#dataset1').getCurrentItem().post,
postImage: $w('#uploadButton1').startUpload,
_createdDate: $w('#dataset1').getCurrentItem()._createdDate,  
numberOfLikes : "0"
}
wixData.insert("userPosts", toInsert)
.then( (results) => {
let item = results; 
console.log("OK")

```

dataset2 is the dataset that contains user infos, reading from the userProfile database  
dataset1 is the dataset that contains all the elements of the post, writing to the userPosts database

instead of linkink the button2 to dataset1 with action ‘submit’, i use the code above, and everything is fine as long as it concerns the post and \_createdDate fields. But I cannot find a way to sent the image i select (via uploadButton1) to the database.  
I have also tried to use:

```javascript
postImage: $w('#dataset1').getCurrentItem().postImage,

```

but the image is not added in the postImage field.  
Anyone has a clue?  
Thank you

---

<div class="post-metadata">

**Author:** ![ademontis](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ademontis/32/23012_2.png) [@ademontis](https://forum.wixstudio.com/u/ademontis)\
**Post date:** [September 8, 2020, 6:12pm UTC](https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484/2 "2020-09-08T18:12:22Z")

</div>

I am still stuck at this problem. In the meanwhile i tried another approach using URLs, but it does not look to work either.  
What i did is to detach the link of the image placeholder from the dataset, and use code to write the image url in the dataase.  
In the ‘New Post’ lightbox i used:

```javascript
if($w("#uploadButton1").value.length > 0) {
     $w("#uploadButton1").startUpload()
      .then( (uploadedFile) => {
         $w("#thumbImage").src = uploadedFile.url;
       })

```

to send the result of the uploadButton1 to the thumbImage placeholder image, and the thumbImage correctly dislays the image i have uploaded.  
Then i use:

```javascript
let toInsert = {
postCreatorId: $w('#dataset2').getCurrentItem()._id,
postCreatorImage: $w('#dataset2').getCurrentItem().profileImage,
postCreator: $w('#dataset2').getCurrentItem().fullName,  
post: $w('#dataset1').getCurrentItem().post,
postImageUrl: $w('#thumbImage').src, //this is the image placeholder
_createdDate: $w('#dataset1').getCurrentItem()._createdDate,  
numberOfLikes : "0"
}

wixData.insert("userPosts", toInsert)

```

to send all data to the database, included the image url.  
The Database contains a field set as URL called postImageUrl  
which is filled with this:

![](https://us1.discourse-cdn.com/wix/original/3X/a/7/a7315e4fcfeb33a330844ba1e4db1580cbc309b2.jpeg)

In the dynamic page where all posts appear (with relevant image)  
i use this code:

```javascript
$w.onReady( () => {
$w("#image1").src = ('#userPosts').postImageUrl;

```

where image1 is the image placeholder where i want to show the image of the post, and userPosts is the database.

It doesn’t seem to work, because image1 is filled with a blue placeholder not with the image corresponding to the URL saved in the database.

Anyone has a clue?

---

<div class="post-metadata">

**Author:** ![J.D](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/j.d/32/7312_2.png) [@J.D](https://forum.wixstudio.com/u/J.D)\
**Post date:** [September 8, 2020, 7:23pm UTC](https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484/3 "2020-09-08T19:23:07Z")

</div>

I didn’t read your second question, but as for your first see in **blue** :

```javascript
function uploadFile(){
return $w('#uploadButton1').startUpload().then(r => r.url);
}
export async function button2_click(event) {
 let toInsert = {
//.....etc....
postImage: await uploadFile(),
//etc....

```

[FIXED]

---

<div class="post-metadata">

**Author:** ![ademontis](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/ademontis/32/23012_2.png) [@ademontis](https://forum.wixstudio.com/u/ademontis)\
**Post date:** [September 9, 2020, 6:40am UTC](https://forum.wixstudio.com/t/uploading-image-in-database-via-corvid/38484/4 "2020-09-09T06:40:43Z")

</div>

Thank you so much J.D. it works perfectly!
