question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for image/file uploads

See original GitHub issue

Hello!

We widely use trpc.io and we love it! One use case that recently popped up is being able to use other request content types like multipart/form-data. Is that currently supported by the library? I’m wondering if it’d be just a custom link.

Thank you so much for maintaining this great library.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mesmerlordcommented, Mar 2, 2022

I’m guessing this is for uploading files, I’ve had similar issues. First I tried just base64 encoding the image/file , but next seems to have a limit of 4mb for files which is often not enough. Then I went and tried to just create an API endpoint outside of tRPC to just allow multipart file uploads using multer, but wasn’t having much success with it either. In the end I went with a sort of hybrid approach, using tRPC endpoint to receive filename, filetype, user info etc, then using S3 to create a signedUrl(with expiration, content type limit, and file size limit) only for authenticated users, then users can use that link to directly upload to S3 bucket. Works great

If my guess is right, you only used trpc router endpoint just to get signedurl and you uploaded the file directly to the signedurl from the client using fetch/axios(put), right?

UPDATE: Saw your example at https://github.com/mesmerlord/bazosClone/blob/main/src/components/listingsAdd/DropImage.tsx#L88

Yep and on the server side its : https://github.com/mesmerlord/bazosClone/blob/7c60dce17d626b6a4f2eb375eb3b23ffc7cac076/src/server/routers/photos.ts#L18

Hope you found it useful.

1reaction
KATTcommented, Mar 6, 2022

FYI you can do this to circumvent the 4mb limit:

import { createContext } from 'server/context';
import { appRouter } from 'server/routers/_app';
import * as trpcNext from '@trpc/server/adapters/next';


export default trpcNext.createNextApiHandler({
  router: appRouter,
  /**
   * @link https://trpc.io/docs/context
   */
  createContext,
  // [...]
});

/**
 * @link https://nextjs.org/docs/api-routes/api-middlewares#custom-config
 */
export const config = {
  api: {
    bodyParser: {
      sizeLimit: '20mb',
    },
  },
};

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support image file upload in .NET Core Web API
1 Answer 1 · Media types which are supported by service which define what formats of data can be uploaded correctly to the...
Read more >
ImgBB — Upload Image — Free Image Hosting
Free image hosting and sharing service, upload pictures, photo host. Offers integration solutions for uploading images to forums.
Read more >
Excellent for adding support to new image file formats
Excellent plugin. Even if the description doesn't say it, this plugin allows AVIF file uploads in WordPress in two steps: – Add functions.php...
Read more >
Troubleshoot creative uploads - Display & Video 360 Help
The most common reason you may have problems uploading an audio, video, or image file is if the file type is not supported...
Read more >
Image/file upload problem on Project:Support desk - MediaWiki
Hi! On these picture is my problem. They dont appear on MediaWiki when i upload them. What can be the problem? Thanks for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found