npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-background-upload-client

v1.0.6

Published

Handle multipart file uploads to your Graphql server from your React Native app.

Downloads

11

Readme

react-native-background-upload-client

Handle multipart file uploads to your GraphQL server from your React Native app with Apollo.

Currently only supports iOS.

(Forked from "react-native-background-upload")

Installation

1. Install package

npm install --save react-native-background-upload-client

2. Link Native Code

Autolinking (React Native >= 0.60)

iOS

cd ./ios && pod install && cd ../

Automatic Native Library Linking (React Native < 0.60)

react-native link react-native-background-upload-client

Or, Manually Link It

iOS

  1. In the XCode's "Project navigator", right click on your project's Libraries folder ➜ Add Files to <...>
  2. Go to node_modulesreact-native-background-upload-clientios ➜ select RNGraphqlFileUploader.xcodeproj
  3. Add RNGraphqlFileUploader.a to Build Phases -> Link Binary With Libraries

3. Expo

To use this library with Expo one must first detach (eject) the project and follow step 2 instructions. Additionally on iOS there is a must to add a Header Search Path to other dependencies which are managed using Pods. To do so one has to add $(SRCROOT)/../../../ios/Pods/Headers/Public to Header Search Path in RNGraphqlFileUploader module using XCode.

Usage


// Simply remove the standard apollo createUploadLink...
import { createUploadLink, } from 'apollo-upload-client'

// ... and replace it with this!
import { createUploadLink, } from 'react-native-background-upload-client'

Setting up Apollo Client for File Uploads

This section provides an in-depth example of setting up the Apollo Client and using react-native-background-upload-client to upload a file to your GraphQL server from your React Native app. Ensure you have these additional npm packages installed:

npm install @apollo/client apollo-upload-client


import { createUploadLink, } from 'react-native-background-upload-client'
import { ApolloClient, InMemoryCache, useMutation, gql, } from '@apollo/client'
import { ReactNativeFile, } from 'apollo-upload-client'

// Define your GraphQL server URL
const serverUrl = 'https://your-server-url/graphql'

// Initialize the Apollo Client
const apolloClient = new ApolloClient({
  link: createUploadLink({ uri: serverUrl, }),
  cache: new InMemoryCache(),
})

function MyReactComponent() {
  // Define and use your GraphQL mutation within a functional component
  const [uploadFile] = useMutation(gql`
    mutation($file: Upload) {
      uploadFile(input: { image: $file })
    }
  `)

  // Upload the file to your server within an asynchronous function
  const handleUpload = async () => {
    const response = await uploadFile({
      variables: {
        file: new ReactNativeFile({ uri: 'path-to-file', name: 'file', }),
      },
    })
  }

  return (
    // UI components here
  )
}