最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

qr code - Using QRcode, in some unknown cases, QRcode doesn't generate a fit qr image - Stack Overflow

matteradmin5PV0评论

I am trying to generate QRcode with "qrcode".

I am able to do it, but in some unknown cases, it generates code that cannot be shown and present like it cannot be loaded.

For example, when I write "arad", it generates qr code, but when I add "1", it does not.

It also is not working if I enter numbers only, or just one letter.

I couldn't understand the exact cases which it's not working.

This is my client API to the backend:

import { Body, Controller, Get, Param, Put } from '@nestjs/common';
import { AppService } from './app.service';

let qr;

@Controller("/users")
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get()
  getHello(): string {
    return qr;
  }

  @Put(":id")
  restaurantQRCdoe(@Param('id') id: string, @Body('img') qrCode: string) {
    qr = qrCode;
  }
}

and this is my client api to backend:

import axios from "axios";

const baseBackendURL = `http://localhost:5006/users/`;
export class UsersHttp{

    static async postNewRestaurantQRCode(qrCode: string) {
        axios({
            method: 'put',
            url: baseBackendURL + "arad11",
            data: {
                img: qrCode + "asf"
            }
        })
    }

    static async getQR(){
        return await axios({
            url: baseBackendURL,
            method: 'get',
        });
    }
}

This is my client component:

import { useCallback, useEffect, useState } from "react";
import {UsersHttp} from "../usersHttp/users";
import QRcode from "qrcode";

export function Restaurant () {
    const [username, setUserName] = useState("");
    const [src, setSrc] = useState("");
    const [qr, setqr] = useState();

    const qrGenerator = useCallback(() => {
        QRcode.toDataURL(`/${username}`).then((setSrc));
    },[username]);
    
    const sendToBackend = useCallback(async () => {
        await UsersHttp.postNewRestaurantQRCode(src.toString());
    },[src]);

    const getQRFromBackend = useCallback(async () => { 
         const res = (await UsersHttp.getQR()).data;
         setqr(res);
    },[]);

    useEffect(() => {
        console.log("arad", qr);
    },[qr]);

    return(
        <>
            <input
                placeholder="insert restaurant name"
                value={username}
                onChange={(text) => setUserName(text.target.value)}
            />
            <button type="submit" onClick={qrGenerator}>click here</button>
            <img src={qr}></img>
            <button type="submit" onClick={sendToBackend}>click</button>
            <button type="submit" onClick={getQRFromBackend}>click get qr code</button>
            

        </>
    )
}
Post a comment

comment list (0)

  1. No comments so far