# Not able to override creation default route

**URL:** <https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907>\
**Category:** Help me!\
**Tags:** howtos\
**Created:** [July 14, 2021, 1:26pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907 "2021-07-14T13:26:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 14, 2021, 1:26pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/1 "2021-07-14T13:26:48Z")

</div>

## Expected behavior

I wanted to override the default routes present so that I could store images in s3 bucket.

## Actual behavior

Whenever I am trying to override the default route, always the default route is being called instead of the other one.

## Failure Logs

It prints the image parsed data and shows the following error in admin panel :-

```javascript
Ads creation failed: value too long for type character varying(255)

```

## Context

I have implement the overrided route in `route/ads.js` as said in the documentation.

---

<div class="post-metadata">

**Author:** ![Simon\_BRAMI1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/simon_brami1/32/2753_2.png) [@Simon\_BRAMI1](https://community.forestadmin.com/u/Simon_BRAMI1)\
**Post date:** [July 14, 2021, 7:32pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/2 "2021-07-14T19:32:22Z")

</div>

Hi @Nikhilesh_Ram,

It seems like your input value is too long for the type of field you’re using on your Postgres DB, I suggest you switch your Postgres field to “text” instead?

Let me know if that helps

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 14, 2021, 8:15pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/3 "2021-07-14T20:15:43Z")

</div>

Yes but I want to store the image in amazon bucket instead of my postgresql database. So for that also do I have to change the datatype.

---

<div class="post-metadata">

**Author:** ![Simon\_BRAMI1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/simon_brami1/32/2753_2.png) [@Simon\_BRAMI1](https://community.forestadmin.com/u/Simon_BRAMI1)\
**Post date:** [July 15, 2021, 7:37am UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/4 "2021-07-15T07:37:51Z")

</div>

You can still do that, if you extend the route, you can upload your file on your S3 and then store the image URL in your DB, but your DB datatype should be greater (so basically a “text”).

The type “character varying(255)” sets the limit of characters explicitly to 255.

Which DB field is concerned by your error?

if you want to update your field type you can run this query:

```sql
ALTER TABLE table_name ALTER COLUMN column_name TYPE text;

```

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 15, 2021, 8:45am UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/5 "2021-07-15T08:45:59Z")

</div>

The image field which is of STRING datatype is throwing the error. But I need to store the image by overriding the route.  
This will reduce the amount of computations.

@Simon_BRAMI1

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [July 15, 2021, 10:22am UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/6 "2021-07-15T10:22:56Z")

</div>

Hi @Nikhilesh_Ram,

As I understand your need, you need an image (coming from S3) to be present alongside other fields of a record.  
I suggest the following:

- Create a smart field for the image field: (doc [here](https://docs.forestadmin.com/documentation/reference-guide/fields/create-and-manage-smart-fields)) (put this in fields section in forest/yourModel.js:)

```javascript
   {
      field: 'myImageField',
      type: 'File',
      get: (album) => {
        // code to get the image from record+s3
      },
      set: (record, myimage) => {
        // code to send the image to S3
      }
    }

```

- Follow [this example](https://docs.forestadmin.com/woodshop/how-tos/upload-files-to-s3) to get/store an image from S3. The example is for a smart action but the server code is the same.
- To send larger images, configure your server to allow it. [This thread](https://community.forestadmin.com/t/maximum-file-size-in-a-smart-action-field-file/173) matches this.

Regards

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 15, 2021, 3:16pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/7 "2021-07-15T15:16:15Z")

</div>

I have implemented the smart action method, but I want to override the default route and do it to reduce the amount of computations again.

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [July 15, 2021, 3:34pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/8 "2021-07-15T15:34:46Z")

</div>

I don’t understand, which computations do you plan to reduce?  
The solution above does not contain any useless computation.  
If you mean about json-parsing the body, this will be done even with a route override.

Whatever, you will find [here](https://docs.forestadmin.com/documentation/v/v6/reference-guide/routes/extend-a-route) informations to override a route.

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 15, 2021, 4:06pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/9 "2021-07-15T16:06:58Z")

</div>

The solution of smart action firstly stores the ads data and then by clicking the smart action, I upload the image and then the image field in the db gets updated. Rather if I could override the default route then I could change the image field coming with the other data and store it in the db by just a create query.

I tried implementing the override default route by reading the documentation but forest is still taking the default route instead of the override one.

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [July 16, 2021, 9:16am UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/10 "2021-07-16T09:16:32Z")

</div>

Ok, I think we misunderstood for one thing,

It is not needed to implement a smart action.  
The example of smart action just contains code showing how to put/get an image for S3.

[Creating a smart field](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/6) really looks what you need to implement an image field stored on S3.

Regards

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 16, 2021, 11:45am UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/11 "2021-07-16T11:45:04Z")

</div>

I want to store the image on s3 and then the link has to be stored in the database.  
So for this purpose since the image field doesn’t have BLOB type neither is required.  
The default route tries to store the image in the database which would definitely won’t be successful.  
So the execution procedure needs to be like this :-

```javascript
1. Image has to be stored on s3.
2. The s3 url has to be overwritten in the image coming from admin panel.
3. The insert query has to take place.

```

So for this I need to override the default route.  
I hope this gives some clarity.

---

<div class="post-metadata">

**Author:** ![Sliman\_Medini](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/sliman_medini/32/19_2.png) [@Sliman\_Medini](https://community.forestadmin.com/u/Sliman_Medini)\
**Post date:** [July 16, 2021, 12:27pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/12 "2021-07-16T12:27:04Z")

</div>

Ok,

It’s clear, thank you.

To do this a route override is not needed. A smart field is recommended:

- Define a smart field `image` for the image content (as described [above](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/6), no blob in your db)
- Define a field `imageUrl` on the model to store the URL
- In the smart field setter, send the image to S3 and then update the `imageUrl` field (example [here](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/6))

So the link will be stored in the database 👌

Let me know if that’ ok.

---

<div class="post-metadata">

**Author:** ![Nikhilesh\_Ram](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nikhilesh_ram/32/2601_2.png) [@Nikhilesh\_Ram](https://community.forestadmin.com/u/Nikhilesh_Ram)\
**Post date:** [July 16, 2021, 1:58pm UTC](https://community.forestadmin.com/t/not-able-to-override-creation-default-route/2907/13 "2021-07-16T13:58:49Z")

</div>

Got it thank you so much for the help.

@Sliman_Medini @Simon_BRAMI1
